I have the following objects structure
public interface IParser {}
public interface IAction : IParser {}
public interface ICommand : IParser {}
//impl
public class Action1 : IAction {}
public class Command1 : ICommand {}
//registration
container.Register<IAction, Action1>();
container.Register<ICommand, Command1>();
//resolve
var parsersList = container.Resolve<IList<IParser>>() //expected: parsersList.Count=2 actual count=0
Is there any way to make 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 am 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 back individual registrations lines above, Resolve works for IAction and ICommand but not for IParser.
It seems that RegisterMany
is not registering parent types properly...
Edit2:
I changed my registration to following, 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 type of the first registered mapping, in this case ICommand
I am using DryIOC v2.6.2