Skip to content

Commit ecb97e9

Browse files
committed
repro the failing case for the #678
1 parent 3840dfd commit ecb97e9

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

btcompile_only.bat

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ setlocal EnableDelayedExpansion
33

44
rem Calculate start time
55
set started_at=%time%
6-
set /a started_at_ms=%started_at:~0,2%*24*60*100+%started_at:~3,2%*60*100+%started_at:~6,2%*100+%started_at:~9,2%
6+
set /a started_at_ms=1%started_at:~0,2%*24*60*100-100+%started_at:~3,2%*60*100+%started_at:~6,2%*100+%started_at:~9,2%
77

88
echo:
99
echo:# Build and Run TestRunner on .NET 8.0
@@ -15,7 +15,7 @@ if %ERRORLEVEL% neq 0 goto :error
1515

1616
rem Calculate elapsed time
1717
set finished_at=%time%
18-
set /a finished_at_ms=%finished_at:~0,2%*24*60*100+%finished_at:~3,2%*60*100+%finished_at:~6,2%*100+%finished_at:~9,2%
18+
set /a finished_at_ms=1%finished_at:~0,2%*24*60*100-100+%finished_at:~3,2%*60*100+%finished_at:~6,2%*100+%finished_at:~9,2%
1919
set /a ellapsed_ms=%finished_at_ms%*10-%started_at_ms%*10
2020

2121
echo:

test/DryIoc.IssuesTests/GHIssue678_Scope_is_lost_in_diposable_service.cs

+19-9
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,26 @@ public class Context
6464

6565
public class Strategy
6666
{
67+
public Context ContextFromConstructor { get; }
68+
public Context ContextResolveWithInjectedResolver { get; }
6769
public Strategy(Context context, IResolver resolver)
6870
{
69-
var resolvedContext = resolver.Resolve<Context>();
71+
ContextFromConstructor = context;
72+
ContextResolveWithInjectedResolver = resolver.Resolve<Context>();
7073
}
7174
}
7275

7376
public class ServiceC<TContext> : IDisposable
7477
{
78+
public Strategy Strategy { get; }
79+
public Context Context { get; }
7580
public ServiceC(Strategy strategy, Context context)
7681
{
82+
Strategy = strategy;
83+
Context = context;
7784
}
7885

79-
public void Dispose()
80-
{
81-
}
86+
public void Dispose() { }
8287
}
8388

8489
public class ServiceB
@@ -98,13 +103,16 @@ public void Do()
98103
scope.Use(_context);
99104

100105
var context = scope.Resolve<Context>();
106+
Assert.AreEqual("value", context.Value);
101107

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);
104111

105-
// here context.value is null
106-
// here resolvedContext.value is "value" - resolvedContext is resolved from injected IResolver
107112
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);
108116
}
109117
}
110118

@@ -123,7 +131,9 @@ public ServiceA(IContainer container, Context context, ServiceB serviceB)
123131

124132
public void Do()
125133
{
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
127137

128138
_context.Value = "value";
129139

0 commit comments

Comments
 (0)