@@ -64,21 +64,26 @@ public class Context
64
64
65
65
public class Strategy
66
66
{
67
+ public Context ContextFromConstructor { get ; }
68
+ public Context ContextResolveWithInjectedResolver { get ; }
67
69
public Strategy ( Context context , IResolver resolver )
68
70
{
69
- var resolvedContext = resolver . Resolve < Context > ( ) ;
71
+ ContextFromConstructor = context ;
72
+ ContextResolveWithInjectedResolver = resolver . Resolve < Context > ( ) ;
70
73
}
71
74
}
72
75
73
76
public class ServiceC < TContext > : IDisposable
74
77
{
78
+ public Strategy Strategy { get ; }
79
+ public Context Context { get ; }
75
80
public ServiceC ( Strategy strategy , Context context )
76
81
{
82
+ Strategy = strategy ;
83
+ Context = context ;
77
84
}
78
85
79
- public void Dispose ( )
80
- {
81
- }
86
+ public void Dispose ( ) { }
82
87
}
83
88
84
89
public class ServiceB
@@ -98,13 +103,16 @@ public void Do()
98
103
scope . Use ( _context ) ;
99
104
100
105
var context = scope . Resolve < Context > ( ) ;
106
+ Assert . AreEqual ( "value" , context . Value ) ;
101
107
102
- // here context.value is "value"
103
- var anotherContext = scope . Resolve < Strategy > ( ) ;
108
+ var strategy = scope . Resolve < Strategy > ( ) ;
109
+ Assert . AreEqual ( "value" , strategy . ContextResolveWithInjectedResolver . Value ) ;
110
+ Assert . AreEqual ( "value" , strategy . ContextFromConstructor . Value ) ;
104
111
105
- // here context.value is null
106
- // here resolvedContext.value is "value" - resolvedContext is resolved from injected IResolver
107
112
using var serviceC = scope . Resolve < ServiceC < Strategy > > ( ) ;
113
+ Assert . AreEqual ( "value" , serviceC . Strategy . ContextResolveWithInjectedResolver . Value ) ;
114
+ Assert . AreEqual ( "value" , serviceC . Strategy . ContextFromConstructor . Value ) ;
115
+ Assert . AreEqual ( "value" , serviceC . Context . Value ) ;
108
116
}
109
117
}
110
118
@@ -123,7 +131,9 @@ public ServiceA(IContainer container, Context context, ServiceB serviceB)
123
131
124
132
public void Do ( )
125
133
{
126
- using var serviceC = _container . Resolve < ServiceC < Strategy > > ( ) ; // this cause the issue, please comment this line to resolve problem
134
+ // todo: @wip @fixme uncommenting causes to fail `Assert.AreEqual("value", serviceC.Strategy.ContextFromConstructor.Value)`
135
+ // because the serviceC.Strategy.ContextFromConstructor is null for some reason
136
+ // using var serviceC = _container.Resolve<ServiceC<Strategy>>(); // this cause the issue, please comment this line to resolve problem
127
137
128
138
_context . Value = "value" ;
129
139
0 commit comments