本文介绍了vNext依赖注入通用接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了一个ASP.Net vNext的Web API
我已经成功地使用一个简单的界面依赖inection像这样的:
services.AddScoped< ILinearRegressionCalculator,LinearRegressionCalculator>();
不过,我无法弄清楚如何做一个通用接口依赖inection。
如何设置依赖注入这个接口:
公共接口IMongoConnectionHandler< T>其中T:IMongoEntity
解决方案
下面是一个例子:(;>)的typeof(OptionsManager<>))ServiceDescriptor.Singleton(typeof运算(IOptions<); $ C $ p>
C>
来源:
的
I have created an ASP.Net vNext Web API.
I have successfully used the dependency inection with a simple interface such as this:
services.AddScoped<ILinearRegressionCalculator, LinearRegressionCalculator>();
However, I can't figure out how to do dependency inection with a Generic Interface.
How do I setup dependency injection for this interface:
public interface IMongoConnectionHandler<T> where T : IMongoEntity
解决方案
Following is an example:
services.TryAdd(ServiceDescriptor.Singleton(typeof(IOptions<>), typeof(OptionsManager<>)));
这篇关于vNext依赖注入通用接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!