vNext 依赖注入通用接口 [英] vNext Dependency Injection Generic Interface
本文介绍了vNext 依赖注入通用接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了一个 ASP.Net vNext Web API.
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
推荐答案
以下是一个例子:
services.TryAdd(ServiceDescriptor.Singleton(typeof(IOptions<>), typeof(OptionsManager<>)));
这篇关于vNext 依赖注入通用接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文