You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like bindings that are obtained with ToNamespace() aren't working correctly when used in conjunction with RegisterCommands when there are multiple containers. The following example results in a InjectorException: There are no constructors on the type System.Int32. exception. If you comment out line 17 (this.containerTwo = ...) the code works correctly. Likewises, if I change line 46 to inject AdicMultipleContainerTestClassOne directly it works fine.
using Adic;
using Adic.Container;
using AdicMultipleContainerTest.Command;
using AdicMultipleContainerTest.Example;
public class AdicMultipleContainerTestGameRoot : ContextRoot {
private IInjectionContainer containerOne;
private IInjectionContainer containerTwo;
[Inject] private TestCommand Command;
public override void SetupContainers() {
this.containerOne = this.AddContainer<InjectionContainer>()
.RegisterExtension<CommanderContainerExtension>();
this.containerTwo = this.AddContainer<InjectionContainer>();
this.containerOne.Bind<IAdicMultipleContainerTestClass>().ToNamespace("AdicMultipleContainerTest.Example");
this.containerOne.RegisterCommands("AdicMultipleContainerTest.Command");
}
public override void Init() {
this.Inject();
this.Command.Execute();
}
}
namespace AdicMultipleContainerTest.Example
{
public class AdicMultipleContainerTestClassOne : IAdicMultipleContainerTestClass {
public int Integer { get { return 999; }}
}
public class AdicMultipleContainerTestClassTwo : IAdicMultipleContainerTestClass {
public int Integer { get { return 111; } }
}
public interface IAdicMultipleContainerTestClass {
int Integer { get; }
}
}
namespace AdicMultipleContainerTest.Command
{
public class TestCommand : Adic.Command {
[Inject] private IAdicMultipleContainerTestClass[] TestClasses;
public override void Execute(params object[] parameters) {
UnityEngine.Debug.Log(this.TestClasses[0].Integer);
}
}
}
The text was updated successfully, but these errors were encountered:
I'll take a look and release a fix on the next version.
Additionally, speaking about multiple containers, I'm working towards releasing a subcontainer system, so it's easy to have different containers working together. If you have any ideas on the subject, just drop a comment to the #41 issue!
The problem occurs because Adic is trying to re-inject TestCommand on AdicMultipleContainerTestGameRoot from containerTwo, which doesn't contain a binding to IAdicMultipleContainerTestClass. An exception when trying to instantiate interfaces was added.
The solution is to prevent reinjection if the field/property has already been injected.
It looks like bindings that are obtained with ToNamespace() aren't working correctly when used in conjunction with RegisterCommands when there are multiple containers. The following example results in a InjectorException: There are no constructors on the type System.Int32. exception. If you comment out line 17 (this.containerTwo = ...) the code works correctly. Likewises, if I change line 46 to inject AdicMultipleContainerTestClassOne directly it works fine.
The text was updated successfully, but these errors were encountered: