Alexandr
Alexandr

Reputation: 3969

FromNewComponentSibling and then reuse

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

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

I want the same instance of RouMainMenuPresenterCompanion to be injected in MainMenuPresenter as ICompanion (FromNewComponentSibling) and reuse this created instance in the future as RouMainMenuPresenterCompanion for any resolver

Example above leads to circular dependency. How can I solve my problem?

Upvotes: 1

Views: 132

Answers (1)

Steve Vermeulen
Steve Vermeulen

Reputation: 1455

I might not understand correctly but could you just change it to this?

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

Edit: This is probably more what you were looking for:

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

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

Upvotes: 1

Related Questions