I have the following object structure
public interface IParser {} public interface IAction : IParser {} public interface ICommand : IParser {}
Is there any way to do some kind of binding between these parent and child interfaces in DryIOC?
EDIT:
I did some research and found that RegisterMany did the trick, but I'm a bit confused because
//registration //container.Register<IAction, Action1>(); //if I drop these two lines \_____ //container.Register<ICommand, Command1>(); / | container.RegisterMany<Action1>(); // and use these lines | container.RegisterMany<Command1>(); | //resolve | var parsersList = container.Resolve<IList<IParser>>() //WORKS Count = 2 | container.Resolve<IAction>() //not working Unable to resolve IAction <---| container.Resolve<ICommand>() //Same here for ICommand <---| container.Resolve<IParser>() //not working either
If I uncomment the individual log lines above, Resolve works for IAction and ICommand, but not for IParser.
RegisterMany seems to not register parent types correctly ...
Edit2:
I changed my registration to the next using RegisterMapping
container.Register<IAction, Action1>(); container.Register<ICommand, Command1>(); container.RegisterMapping<IParsable, ICommand>(); //1st registered mapping container.RegisterMapping<IParsable, IAction>(); container.Resolve<IList<IParser>>().Count = 1 //instead of 2.
The item in the IParsers list is of the type of the first registered match, in this case ICommand
I am using DryIOC v2.6.2
source share