@@ -13,33 +13,33 @@ internal class ServiceProvider : IServiceProvider
1313 {
1414 private readonly BindingContext _bindingContext ;
1515
16- private readonly Dictionary < Type , Func < object > > _services ;
16+ private readonly Dictionary < Type , Func < IServiceProvider , object > > _services ;
1717
1818 public ServiceProvider ( BindingContext bindingContext )
1919 {
2020 _bindingContext = bindingContext ?? throw new ArgumentNullException ( nameof ( bindingContext ) ) ;
2121
22- _services = new Dictionary < Type , Func < object > >
22+ _services = new Dictionary < Type , Func < IServiceProvider , object > >
2323 {
24- [ typeof ( ParseResult ) ] = ( ) => _bindingContext . ParseResult ,
25- [ typeof ( IConsole ) ] = ( ) => _bindingContext . Console ,
26- [ typeof ( CancellationToken ) ] = ( ) => CancellationToken . None ,
27- [ typeof ( IHelpBuilder ) ] = ( ) => _bindingContext . ParseResult . Parser . Configuration . HelpBuilderFactory ( _bindingContext ) ,
28- [ typeof ( BindingContext ) ] = ( ) => _bindingContext
24+ [ typeof ( ParseResult ) ] = _ => _bindingContext . ParseResult ,
25+ [ typeof ( IConsole ) ] = _ => _bindingContext . Console ,
26+ [ typeof ( CancellationToken ) ] = _ => CancellationToken . None ,
27+ [ typeof ( IHelpBuilder ) ] = _ => _bindingContext . ParseResult . Parser . Configuration . HelpBuilderFactory ( _bindingContext ) ,
28+ [ typeof ( BindingContext ) ] = _ => _bindingContext
2929 } ;
3030 }
3131
32- public void AddService < T > ( Func < T > factory ) => _services [ typeof ( T ) ] = ( ) => factory ( ) ;
32+ public void AddService < T > ( Func < IServiceProvider , T > factory ) => _services [ typeof ( T ) ] = p => factory ( p ) ;
3333
34- public void AddService ( Type serviceType , Func < object > factory ) => _services [ serviceType ] = factory ;
34+ public void AddService ( Type serviceType , Func < IServiceProvider , object > factory ) => _services [ serviceType ] = factory ;
3535
3636 public IReadOnlyCollection < Type > AvailableServiceTypes => _services . Keys ;
3737
3838 public object GetService ( Type serviceType )
3939 {
4040 if ( _services . TryGetValue ( serviceType , out var factory ) )
4141 {
42- return factory ( ) ;
42+ return factory ( this ) ;
4343 }
4444
4545 return null ;
0 commit comments