commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Most effective way of working with IoC containers and injected verbs?

Open dmoonfire opened this issue 8 years ago • 1 comments

So, I'm fond of IoC builders (Autofac, Ninject, etc). We are building up a command line that has pluggable verbs. In most cases, the IoC containers return actual instances of objects, not types. I'm currently using the system to build up a list of types.

var container = ...;
var verb = container.Resolve<ICommands>();
var verbTypes = verb.Select(v => v.GetType()).ToArray();
var results = Parser.Default.ParseArguments(args, verbTypes);

This can be inefficient. Is there a way of putting the resolved classes directly in without using types or knowing all the verbs ahead of time?

dmoonfire avatar Jan 15 '17 05:01 dmoonfire

No, I think that's the only option. After all, commandline doesn't know anything about your ICommands interface, you have to tell it which types to use. There may be a way to get the types without creating an implementation though, depending on your container.

nemec avatar Jan 17 '17 03:01 nemec