@@ -13,33 +13,33 @@ internal class ServiceProvider : IServiceProvider
13
13
{
14
14
private readonly BindingContext _bindingContext ;
15
15
16
- private readonly Dictionary < Type , Func < object > > _services ;
16
+ private readonly Dictionary < Type , Func < IServiceProvider , object > > _services ;
17
17
18
18
public ServiceProvider ( BindingContext bindingContext )
19
19
{
20
20
_bindingContext = bindingContext ?? throw new ArgumentNullException ( nameof ( bindingContext ) ) ;
21
21
22
- _services = new Dictionary < Type , Func < object > >
22
+ _services = new Dictionary < Type , Func < IServiceProvider , object > >
23
23
{
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
29
29
} ;
30
30
}
31
31
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 ) ;
33
33
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 ;
35
35
36
36
public IReadOnlyCollection < Type > AvailableServiceTypes => _services . Keys ;
37
37
38
38
public object GetService ( Type serviceType )
39
39
{
40
40
if ( _services . TryGetValue ( serviceType , out var factory ) )
41
41
{
42
- return factory ( ) ;
42
+ return factory ( this ) ;
43
43
}
44
44
45
45
return null ;
0 commit comments