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

Allow arrays to be resolved as empty #83

Merged
merged 2 commits into from
Mar 15, 2017
Merged

Conversation

FodderMK
Copy link
Contributor

I wasn't too sure about this one but wanted to make a pull request for it anyway. With the current implementation of Adic the following code causes a InjectorException: Interface "TestGameRoot+IMockInterface" cannot be instantiated. exception:

using Adic;

public class TestGameRoot : ContextRoot {
	[Inject] private IMockInterface[] Test;

	public override void SetupContainers()	{
		var container = this.AddContainer<InjectionContainer>();
		container.resolutionMode = ResolutionMode.ALWAYS_RESOLVE;
		container.Bind<IMockInterface>().ToNamespace("", true);
		this.Inject();
	}

	public override void Init() {}

	public interface IMockInterface {}
}

I understand the reasoning behind the error but I feel that in this situation the end result for the Test property should be an empty array (ie: private IMockInterface[] Test = new IMockInterface[0]) This would fulfill the ALWAYS_RESOLVE requirement (I have a property that has been resolved) while still fitting in with my configuration (no IMockInterface classes defined). This pull request accomplishes that functionality.

This situation has come up because I have platform-specific classes bound to IMockInterface, and in some cases the platform doesn't need an IMockInterface definition. Currently I need to create a fake class like public class NullClass : IMockInterface to have my game run and that doesn't seem correct.

If you would like more details let me know.

@FodderMK
Copy link
Contributor Author

Tweaked solution to check for the specific case of the property being an array of interfaces.

@intentor intentor self-requested a review March 15, 2017 01:42
@intentor intentor self-assigned this Mar 15, 2017
@intentor intentor added this to the v2.26 milestone Mar 15, 2017
@intentor
Copy link
Owner

Hello, @FodderMK!

I do think your solution is very neat! That was a case I've never run into, however I believe is something to be addressed.

Thank you! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants