-
Notifications
You must be signed in to change notification settings - Fork 9
Dependency Injection
Matthias Beerens edited this page Dec 28, 2018
·
5 revisions
To use a custom DI/IoC container you will need to create a custom resolver. This resolver will pass the work on to the underlying DI/IoC container.
using MatthiWare.CommandLine.Abstractions;
public class CustomResolver : IContainerResolver
{
private readonly IContainer _container;
public CustomResolver(IContainer container)
{
_container = container;
}
public T Resolve<T>()
{
return _container.Resolve<T>();
}
}
Now you can use it as following
private readonly IContainer _container;
public static void Main(string[] args)
{
var parser = new CommandLineParser<OptionModel>(new CustomResolver(_container));
var result = parser.Parse(args);
}