Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Zenject 6 Upgrade] Not possible to bind multiple interfaces to the same implementation when using WithId anymore? #277

Open
leonidumanskiy opened this issue Dec 2, 2022 · 0 comments

Comments

@leonidumanskiy
Copy link

leonidumanskiy commented Dec 2, 2022

Consider this example:

interface IAnimal { ... }

interface ICanine { ... }
interface IFeline { ... }

class Dog : IAnimal, ICanine { ... }
class Cat : IAnimal, IFeline { ... }


Container.Bind<ICanine>().To<Dog>().AsSingle();
Container.Bind<IFeline>().To<Cat>().AsSingle();

Container.Bind<IAnimal>().WithId("dog").To<Dog>().AsSingle();
Container.Bind<IAnimal>().WithId("cat").To<Cat>().AsSingle();

Before the upgrade in the version 5.5, this worked and you could resolve a Dog using both traditional injection into e.g. a constructor (ICanine), as well as via something like an AnimalFactory when you have an ID.

Now with the latest Zenject, I am getting:

ZenjectException: Assert hit! Attempted to use AsSingle multiple times for type 'Dog'.  As of Zenject 6+, AsSingle as can no longer be used for the same type across different bindings.  See the upgrade guide for details.

I am unsure how to resolve it since you can't use WithId() on a single binding where first interface needs to resolve without an ID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant