Skip to content

ToNamespace and CommanderContainerExtension bindings not resolving correctly when using multiple containers #73

@FodderMK

Description

@FodderMK

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);
		}
	}
}

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions