ToSingleton() with resolutionMode=RETURN_NULL throws exception
FodderMK opened this issue · comments
Kevin Yockey commented
Using Adic 2.20.1 the following code:
public class Test1 {
[Inject] public Test2 Foo;
}
public class Test2 {
public string Bar = "Bar";
}
public class GameRoot : ContextRoot {
public override void SetupContainers() {
var container = this.AddContainer<InjectionContainer>();
container.resolutionMode = ResolutionMode.RETURN_NULL;
container.Bind<Test2>().ToSingleton();
container.Bind<Test1>().ToSingleton();
}
}
throws the following exception on the container.Bind<Test1>().ToSingleton()
line:
NullReferenceException: Object reference not set to an instance of an object
Adic.Injection.Injector.OnBeforeAddBinding (IBinder source, Adic.Binding.BindingInfo& binding) (at Assets/Adic/Scripts/Framework/Injection/Injector.cs:517)
Adic.Binding.Binder.AddBindingToDictionary (Adic.Binding.BindingInfo binding) (at Assets/Adic/Scripts/Framework/Binding/Binder.cs:71)
Adic.Binding.Binder.AddBinding (Adic.Binding.BindingInfo binding) (at Assets/Adic/Scripts/Framework/Binding/Binder.cs:62)
Adic.Binding.BindingFactory.AddBinding (System.Object value, BindingInstance instanceType) (at Assets/Adic/Scripts/Framework/Binding/BindingFactory.cs:178)
Adic.Binding.BindingFactory.ToSingleton () (at Assets/Adic/Scripts/Framework/Binding/BindingFactory.cs:38)
GameRoot.SetupContainers () (at Assets/_/Scripts/GameRoot.cs:36)
Adic.ContextRoot.Awake () (at Assets/Adic/Scripts/Extensions/ContextRoot/ContextRoot.cs:69)
If I change the ToSingleton()
methods to ToSelf()
OR if I change the resolution mode to ALWAYS_RESOLVE
then the bindings work correctly.
André "Intentor" Martins commented
Thanks for the feedback! I'll look into it and release a fix on the next version!