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

Cannot Unbind/Rebind AsSingle bindings #19

Open
Bit-Rot opened this issue Jun 15, 2019 · 1 comment
Open

Cannot Unbind/Rebind AsSingle bindings #19

Bit-Rot opened this issue Jun 15, 2019 · 1 comment

Comments

@Bit-Rot
Copy link

Bit-Rot commented Jun 15, 2019

After creating a binding as a singleton, that value cannot then be unbound/rebound via Container.Unbind() or Container.Rebind().

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

Example 1:

Container.Bind<string>().To<string>().FromInstance("test1").AsSingle();
Container.Unbind<string>();
Container.Bind<string>().To<string>().FromInstance("test2").AsSingle();

Example 2:

Container.Bind<string>().To<string>().FromInstance("test1").AsSingle();
Container.Rebind<string>().To<string>().FromInstance("test2").AsSingle();

My use case is that I'd like to have a separate singleton instance of a class for each container. I was hoping to run the following installer in each container, so that each container has some contextual information I can use to improve logging:

IContainerInfo containerInfo = new ContainerInfo(m_Settings.ContainerName);
Container.Rebind<IContainerInfo>().To<IContainerInfo>().FromInstance(containerInfo).AsSingle();
@grofit
Copy link

grofit commented Dec 23, 2020

I am hitting this too but when using the non generic version where you pass in the type as an arg. I remember a while ago that there was some discussion around unbind and there may have been another method which ACTUALLY unbound something but for the life of me cannot remember what it was (or I am completely wrong).

Either way I am having things not being unbound when calling Unbind(type) on them.

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

2 participants