嗨,我需要在 Unity 中为同一接口注册两种类型。
这是我正在尝试做的一个例子:
container.RegisterType(typeof(IPerson) , typeof(Administrator))
container.RegisterType(typeof(IPerson) , typeof(Director))
public class School{
private IPerson _director;
public School(IPerson director){
_director = director;
}
}
public class Building{
private IPerson _administrator;
public Building(IPerson administrator){
_administrator= administrator;
}
}
我将如何告诉 Unity 对于班级 School 我想要一个 Director 实例而对于班级 Building 我想要一个 Administrator 实例?