【发布时间】:2018-12-27 07:11:14
【问题描述】:
我正在使用 Unity 的依赖注入。即 Unity.Mvc5。我从各种程序集中获取所有类型
Assembly assembly = Assembly.LoadFrom(string.Format("{0}\\{1}", AppStartPath, containerElement.InterfaceAssembly));
Assembly assembly2 = Assembly.LoadFrom(string.Format("{0}\\{1}", AppStartPath, containerElement.ConcreteClassAssembly));
Type type = assembly.GetType(containerElement.InterfaceName);
Type type2 = assembly2.GetType(containerElement.ConcreteClass);
现在,当我传递类型时,以下工作:
container.RegisterType<IWarehouseBinController, WarehouseBinController>();
但这不是
container.RegisterType<type.GetTypeInfo().GetType(), type2.GetTypeInfo().GetType()>();
有人知道为什么或如何解决它吗?基本上我想在 ASP.Net MVC 站点中使用它。
【问题讨论】:
-
A
Type实例不是通用参数,这就是它不起作用的原因。我相信有一个 method 接受Type对象而不是通用参数。 -
是的。这是重复的
标签: c# asp.net-mvc generics dependency-injection