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

ToSingleton() with resolutionMode=RETURN_NULL throws exception #54

Closed
FodderMK opened this issue Aug 9, 2016 · 1 comment
Closed

ToSingleton() with resolutionMode=RETURN_NULL throws exception #54

FodderMK opened this issue Aug 9, 2016 · 1 comment
Assignees
Labels
Milestone

Comments

@FodderMK
Copy link
Contributor

FodderMK commented Aug 9, 2016

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.

@intentor intentor added the bug label Aug 10, 2016
@intentor intentor added this to the v2.21 milestone Aug 10, 2016
@intentor intentor self-assigned this Aug 10, 2016
@intentor
Copy link
Owner

Thanks for the feedback! I'll look into it and release a fix on the next version!

@intentor intentor modified the milestones: v2.20.2, v2.21 Aug 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants