获取依赖注入Asp Net Core中的泛型类型

时间:2017-08-29 13:35:15

标签: c# dependency-injection asp.net-core

我想归档所有通用服务的全局解决方案,我有以下代码:

services.AddScoped(typeof(IService<>), provider => ResolveService(genericType));

我需要一个参数,它是解析服务并返回正确实例所需的泛型类型。

在这种情况下,有一种方法可以提取接口所需的通用类型吗?

1 个答案:

答案 0 :(得分:1)

我认为,您应该在课程中使用服务解析器。但你应该知道 - 这是一个anti-pattern

    ---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
<ipython-input-12-4588884f9b0a> in <module>()
----> 1 nx.write_graphml(G, 'C:/Users/my_name/Documents')

<decorator-gen-324> in write_graphml(G, path, encoding, prettyprint)

C:\Users\my_name\Anaconda3\lib\site-packages\networkx\utils\decorators.py in _open_file(func, *args, **kwargs)
    196         if is_string_like(path):
    197             ext = splitext(path)[1]
--> 198             fobj = _dispatch_dict[ext](path, mode=mode)
    199             close_fobj = True
    200         elif hasattr(path, 'read'):

PermissionError: [Errno 13] Permission denied:
相关问题