我对 Unity 应用程序块很陌生,并且在尝试实现以下内容时有点卡住。我有一个父子容器。当我解析子容器的新实例时,我想使用 CreateChildContainer 方法将新的 UnityContainer 注入到构造函数中。
public class RootContainer
{
private IUnityContainer _container;
public RootContainer()
{
_container = new UnityContainer();
_container.RegisterType<IChildContainer, ChildContainer>();
}
}
public interface IChildContainer { }
public class ChildContainer : IChildContainer
{
private IUnityContainer _container;
/* I want to inject the parent.CreateChildContainer() into this constructor */
public ChildContainer(IUnityContainer container)
{
_container = container;
}
}