我有一组接口和类:
public interface IA
{
...
}
public class A: IA
{
...
}
我想把依赖注入的类:
public class MyClass
{
private readonly IA _aRepo;
private readonly IB _bRepo;
private readonly IC _cRepo;
public MyClass(IA aRepo, IB bRepo, IC cRepo)
{
_aRepo = aRepo;
_bRepo = bRepo;
_cRepo = cRepo;
}
}
依赖是:
public class Test
{
private MyClass myClass;
public Test()
{
//original call
//myClass = new MyClass(new A(), new B(), new C());
IUnityContainer container = new UnityContainer();
container.RegisterType<IA, A>();
container.RegisterType<IB, B>();
container.RegisterType<IC, C>();
//not sure what to do here...
container.RegisterType<MyClass>(new InjectionConstructor(new ResolvedParameter<IA>(), new ResolvedParameter<IB>(), new ResolvedParameter<IC>()));
myClass = container.Resolve<MyClass>();
}
}
我是DI的新手,想问一下如何解决MyClass的注入问题,它接受多个接口作为参数?