如何注册通用服务

我打算将我的系统移动到通用服务层。

public interface IAbcService where TEntity : class public class AbcService : IAbcService where TEntity : class 

我尝试了一些东西,但它不起作用。

 services.AddTransient<typeof(IAbcService), AbcService(); .... .... .... 

我正在使用我的一些实体,并且我正在尝试将其添加到属性中。

如何在asp.net核心中注册通用服务?

我之前想尝试完全相同的东西,我让它像这样工作:

 services.AddTransient(typeof(IAbcService<>), typeof(AbcService<>)); services.AddTransient(typeof(IAbcService), typeof(AbcService)); 

请注意不同的结构,这是通过方法中的参数进行注册。

如上所示,使用新的DNX框架包,我们现在可以注册开放和封闭的generics。 尝试一下,这两行都行。

你有没有尝试过

services.AddTransient ,AbcService>()