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

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

我希望将相同的实例RouMainMenuPresenterCompanion注入 MainMenuPresenter 作为ICompanion( FromNewComponentSibling) 并在将来重用这个创建的实例,就像RouMainMenuPresenterCompanion任何解析器一样

上面的示例导致循环依赖。我该如何解决我的问题?

4

1 回答 1

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)
于 2018-05-29T23:52:47.177 回答