Container.Bind<ICompanion>()
.To<RouMainMenuPresenterCompanion>()
.FromNewComponentSibling()
.WhenInjectedInto<MainMenuPresenter>();
Container.Bind<RouMainMenuPresenterCompanion>()
.FromResolve();
我希望将RouMainMenuPresenterCompanion
的同一个实例作为ICompanion
(FromNewComponentSibling
)注入到MainMenuPresenter中,并在将来将此创建的实例重新用作任何解析器的RouMainMenuPresenterCompanion
< / p>
上面的例子导致循环依赖。我怎样才能解决我的问题?
答案 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)