FromNewComponentSibling然后重用

时间:2018-05-27 16:40:09

标签: unity3d zenject

Container.Bind<ICompanion>()
    .To<RouMainMenuPresenterCompanion>()
    .FromNewComponentSibling()
    .WhenInjectedInto<MainMenuPresenter>();

Container.Bind<RouMainMenuPresenterCompanion>()
    .FromResolve();

我希望将RouMainMenuPresenterCompanion的同一个实例作为ICompanionFromNewComponentSibling)注入到MainMenuPresenter中,并在将来将此创建的实例重新用作任何解析器的RouMainMenuPresenterCompanion < / p>

上面的例子导致循环依赖。我怎样才能解决我的问题?

1 个答案:

答案 0 :(得分:1)

我可能听不懂,但你可以改成它吗?

Container.Bind(typeof(ICompanion), typeof(RouMainMenuPresenterCompanion))
    .To<RouMainMenuPresenterCompanion>()
    .FromNewComponentSibling()
    .WhenInjectedInto<MainMenuPresenter>();

编辑:这可能更符合您的要求:

Container.Bind<RouMainMenuPresenterCompanion>()
    .FromNewComponentSibling()
    .WhenInjectedInto<MainMenuPresenter>();

Container.Bind<ICompanion>()
    .To<RouMainMenuPresenterCompanion>()
    .FromResolveGetter<MainMenuPresenter>(p => p.Companion)