【发布时间】:2020-10-06 05:10:20
【问题描述】:
我写了一个类似下面的类
public sealed class SomeAttribute : Attribute, IResultFilter
{
private INotificationhub notificationHub;
public void OnResultExecuting(ResultExecutingContect filterContext)
{
//Need to set value notificationHub by resolving dependency
//some other logic here
}
}
在asp.net core的ConfigureServices中
我写过
services.AddSingleton<INotificationHub, NotificationHub>();
如何解决属性类中的依赖关系。我无法进行构造函数注入。
【问题讨论】:
-
此链接可能有用,用于演示如何注入依赖项操作过滤器。与您类似的用例。 devtrends.co.uk/blog/…
标签: c# asp.net-mvc asp.net-core dependency-injection