我坚持使用相当于这种统一注册的ninject:
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 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();