0
我如何限制类型解析在子UnityContainer?统一约束类型实例解析在子容器
E.g
internal interface ITestInterface
{}
public class Test:ITestInterface
{}
class A
{
public A(ITestInterface testInterface)
{
}
}
class Program
{
static void Main(string[] args)
{
var container = new UnityContainer();
Test test = new Test();
container.RegisterInstance<ITestInterface>(test);
var childContainer = container.CreateChildContainer();
//shoudl resolved normally
container.Resolve<A>();
//should throw exception!
//because i want restrict resolving ITestInterface instance from parent container!
childContainer.Resolve<A>();
}
}
您希望派生容器拥有自己的一组注册吗?所以有些类只能从父容器派生? – PVitt 2011-05-13 11:55:21
它不是派生容器它是子容器。它的重要区别 – void 2011-05-13 12:20:03
是的,我的意思是小孩的容器。抱歉混淆。那么你希望子容器拥有它自己的一组注册? – PVitt 2011-05-13 12:25:50