在.Net core注册一个泛型的服务
public interface IService<T>
{
async Task DoAction();
}
public class Service<T> : IService<T>
{
public async Task DoAction()
{
.... do action
}
}
ServiceCollection.AddScoped<typeof(IService<>), typeof(Service<>)>();
ServiceCollection.AddScoped<typeof(ITInterface<>), typeof(TImplement<>)>(typeof(Service<>));
ServiceCollection.AddScoped(typeof(TImplement<>));
本文介绍如何在.NET Core中注册泛型服务。通过定义泛型接口`IService<T>`及其实现类`Service<T>`,并展示如何使用`ServiceCollection`进行依赖注入。
5万+

被折叠的 条评论
为什么被折叠?



