ssannandeji / Zenject-2019

Dependency Injection Framework for Unity3D
MIT License
2.53k stars 363 forks source link

Possible bug where unbind does not remove binding data #600

Open grofit opened 5 years ago

grofit commented 5 years ago

Scenario

Trying to unbind an existing bound type, then bind it again with a new binding.

Reproduction Scenario

I have created a small reproduction, if you add this code to a default unity project with zenject and add the installer to your scene context:

public interface ISomething
{
    void DoSomething();
}

public class Something : ISomething
{
    public void DoSomething()
    {
        throw new System.NotImplementedException();
    }
}

public class Installer : MonoInstaller
{
    public override void InstallBindings()
    {
        Container.Bind<ISomething>().To<Something>().AsSingle();
        Container.Unbind<ISomething>();
        Container.Bind<ISomething>().To<Something>().AsSingle();
    }
}

Expected Behaviour

There would be no errors and ISomething would be bound to Something as a singleton once.

Actual Behaviour

You will get a validation error that ISomething has been assigned AsSingle multiple times, but I was expecting that it would remove the bindings for ISomething then be replaced with the binding.