所以我有一个接口和类:
public interface IMyInterface<T> where T : ISomeEntity {}
public class MyClass<T> : IMyInterface<T>
where T : ISomeEntity {}
我将有一些需要它的课程:
public class SomeClass : ISomeClass
{
public SomeClass (IMyInterface<AuditEntity> myInterface) {}
}
我已经做了各种各样的事情来让它注册开放通用接口和类,但没有成功。
我只想说这样的话:
container.RegisterType(typeof(MyClass<>)).As(typeof(IMyInterface<>));
如果我必须经历并明确地执行以下操作,那会很烦人:
container.RegisterType<MyClass<AuditEntity>>().As<IMyInterface<AuditEntity>>();
这不应该是小事吗?
你必须使用RegisterGeneric
方法见注册概念 - 开放通用组件 http://docs.autofac.org/en/latest/register/registration.html#open-generic-components
像这样的东西应该有效:
builder.RegisterGeneric(typeof(MyClass<>)).As(typeof(IMyInterface<>));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)