Skip to content

Commit 298f513

Browse files
Expose properties for Inject and Config
1 parent fa1d442 commit 298f513

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/Hyperbee.Expressions/ConfigurationExpression.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ namespace Hyperbee.Expressions;
77
public class ConfigurationExpression : Expression, IDependencyInjectionExpression
88
{
99
private IConfiguration _configuration;
10-
private readonly string _key;
1110
private readonly Type _type;
1211

1312
public ConfigurationExpression( Type type, string key )
1413
{
1514
_type = type;
16-
_key = key;
15+
Key = key;
1716
}
1817

1918
public ConfigurationExpression( Type type, IConfiguration configuration, string key )
2019
{
2120
_type = type;
2221
_configuration = configuration;
23-
_key = key;
22+
Key = key;
2423
}
2524

2625
public void SetServiceProvider( IServiceProvider serviceProvider )
@@ -30,6 +29,7 @@ public void SetServiceProvider( IServiceProvider serviceProvider )
3029

3130
public override ExpressionType NodeType => ExpressionType.Extension;
3231
public override Type Type => _type;
32+
public string Key { get; init; }
3333
public override bool CanReduce => true;
3434

3535
private MethodInfo GetValueMethodInfo => typeof( ConfigurationBinder )
@@ -46,7 +46,7 @@ public override Expression Reduce()
4646
return Call(
4747
null,
4848
GetValueMethodInfo,
49-
[Constant( _configuration ), Constant( _key )] );
49+
[Constant( _configuration ), Constant( Key )] );
5050
}
5151

5252
protected override Expression VisitChildren( ExpressionVisitor visitor )

src/Hyperbee.Expressions/InjectExpression.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ namespace Hyperbee.Expressions;
77
public class InjectExpression : Expression, IDependencyInjectionExpression
88
{
99
private IServiceProvider _serviceProvider;
10-
private readonly string _key;
11-
private readonly Expression _defaultValue;
1210
private readonly Type _type;
1311

1412
public InjectExpression( Type type, IServiceProvider serviceProvider, string key, Expression defaultValue )
1513
{
1614
_type = type;
1715
_serviceProvider = serviceProvider;
18-
_key = key;
19-
_defaultValue = defaultValue;
16+
Key = key;
17+
DefaultValue = defaultValue;
2018
}
2119

2220
public void SetServiceProvider( IServiceProvider serviceProvider )
@@ -26,6 +24,8 @@ public void SetServiceProvider( IServiceProvider serviceProvider )
2624

2725
public override ExpressionType NodeType => ExpressionType.Extension;
2826
public override Type Type => _type;
27+
public string Key { get; init; }
28+
public Expression DefaultValue { get; init; }
2929
public override bool CanReduce => true;
3030

3131
private MethodInfo GetServiceMethodInfo => typeof( ServiceProviderServiceExtensions )
@@ -45,7 +45,7 @@ public override Expression Reduce()
4545

4646
var serviceValue = Variable( _type, "serviceValue" );
4747

48-
var callExpression = _key == null
48+
var callExpression = Key == null
4949
? Call(
5050
null,
5151
GetServiceMethodInfo,
@@ -54,10 +54,10 @@ public override Expression Reduce()
5454
: Call(
5555
null,
5656
GetKeyedServiceMethodInfo,
57-
[Constant( _serviceProvider ), Constant( _key )]
57+
[Constant( _serviceProvider ), Constant( Key )]
5858
);
5959

60-
var defaultExpression = _defaultValue ??
60+
var defaultExpression = DefaultValue ??
6161
Throw( New( ExceptionHelper.ConstructorInfo, Constant( "Service is not available." ) ), _type );
6262

6363
return Block(

0 commit comments

Comments
 (0)