Csharp/C#教程:如何注册通用服务分享


如何注册通用服务

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

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>()

上述就是C#学习教程:如何注册通用服务分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/983264.html

(0)
上一篇 2021年12月19日
下一篇 2021年12月19日

精彩推荐