2

我被与此统一注册等效的 ninjects 卡住了:

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();
4

0 回答 0