使用默认依赖注入在 asp.net 5 中注册 class 时如何指定构造函数
How to specify constructor when registrating class in asp.net 5 with default Dependecy Injection
当 class 具有带参数的构造函数时,是否可以使用 ASP.NET 5
默认值 Dependency Injection
实例化 class?
我想用接受 connection_string
的构造函数注册 Repository
。
更新
我想我可以重新表述这个问题。我想指定在注册 class 时将调用哪个构造函数。 Autofac 有类似的东西。这可能吗?
builder.RegisterType<ConfigReader>()
.As<IConfigReader>()
.WithParameter("configSectionName", "sectionName");
遗憾的是,开箱即用的 DI 容器不支持参数约束。全有或全无。
如果您需要高级功能,您可以切换到另一个 DI 容器,例如您已经提到的并且在 ASP.NET 5.
中受支持的 Autofac
当 class 具有带参数的构造函数时,是否可以使用 ASP.NET 5
默认值 Dependency Injection
实例化 class?
我想用接受 connection_string
的构造函数注册 Repository
。
更新
我想我可以重新表述这个问题。我想指定在注册 class 时将调用哪个构造函数。 Autofac 有类似的东西。这可能吗?
builder.RegisterType<ConfigReader>()
.As<IConfigReader>()
.WithParameter("configSectionName", "sectionName");
遗憾的是,开箱即用的 DI 容器不支持参数约束。全有或全无。
如果您需要高级功能,您可以切换到另一个 DI 容器,例如您已经提到的并且在 ASP.NET 5.
中受支持的 Autofac