Inversion of control 如何使用Unity';ninject儿童容器的s注射剂工厂?

Inversion of control 如何使用Unity';ninject儿童容器的s注射剂工厂?,inversion-of-control,ninject,unity-container,Inversion Of Control,Ninject,Unity Container,我被困在相当于此unity注册的9个对象中: var container = new UnityContainer(); container.RegisterType<MyFactory>(new ContainerControlledLifetimeManager()); // resolve instances once per child container by MyFactory container.RegisterType<IMyInstance>(new

我被困在相当于此unity注册的9个对象中:

var container = new UnityContainer();
container.RegisterType<MyFactory>(new ContainerControlledLifetimeManager());

// resolve instances once per child container by MyFactory
container.RegisterType<IMyInstance>(new HierarchicalLifetimeManager(), 
                                    new InjectionFactory(c => c.Resolve<MyFactory>().GetMyInstance()));
var container=newunitycontainer();
RegisterType(新的ContainerControlledLifetimeManager());
//MyFactory为每个子容器解析一次实例
container.RegisterType(新的层次结构CallifetimeManager(),
新的InjectionFactory(c=>c.Resolve().GetMyInstance());
已尝试执行此操作,但没有任何效果:

var kernel = new StandardKernel();
kernel.Bind<MyFactory>().ToSelf().InSingletonScope();

// context preserving get should do the job for child containers, right?
// thought in call scope ist the equivalent to unity's hierarchical lifetime manager?
kernel.Bind<IMyInstance>().ToMethod(ctx => ctx.ContextPreservingGet<MyFactory>().GetMyInstance())
                          .InCallScope();
var-kernel=new-StandardKernel();
kernel.Bind().ToSelf().InSingletonScope();
//上下文保护get应该为子容器做这项工作,对吗?
//调用范围中的思想是否等同于unity的分层生命周期管理器?
kernel.Bind().ToMethod(ctx=>ctx.ContextPreservingGet().GetMyInstance())
.InCallScope();