Skip to content

Commit

Permalink
repro the failing case for the #678
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Mar 5, 2025
1 parent 3840dfd commit ecb97e9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions btcompile_only.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ setlocal EnableDelayedExpansion

rem Calculate start time
set started_at=%time%
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%
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%

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

rem Calculate elapsed time
set finished_at=%time%
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%
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%
set /a ellapsed_ms=%finished_at_ms%*10-%started_at_ms%*10

echo:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,26 @@ public class Context

public class Strategy
{
public Context ContextFromConstructor { get; }
public Context ContextResolveWithInjectedResolver { get; }
public Strategy(Context context, IResolver resolver)
{
var resolvedContext = resolver.Resolve<Context>();
ContextFromConstructor = context;
ContextResolveWithInjectedResolver = resolver.Resolve<Context>();
}
}

public class ServiceC<TContext> : IDisposable
{
public Strategy Strategy { get; }
public Context Context { get; }
public ServiceC(Strategy strategy, Context context)
{
Strategy = strategy;
Context = context;
}

public void Dispose()
{
}
public void Dispose() { }
}

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

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

// here context.value is "value"
var anotherContext = scope.Resolve<Strategy>();
var strategy = scope.Resolve<Strategy>();
Assert.AreEqual("value", strategy.ContextResolveWithInjectedResolver.Value);
Assert.AreEqual("value", strategy.ContextFromConstructor.Value);

// here context.value is null
// here resolvedContext.value is "value" - resolvedContext is resolved from injected IResolver
using var serviceC = scope.Resolve<ServiceC<Strategy>>();
Assert.AreEqual("value", serviceC.Strategy.ContextResolveWithInjectedResolver.Value);
Assert.AreEqual("value", serviceC.Strategy.ContextFromConstructor.Value);
Assert.AreEqual("value", serviceC.Context.Value);
}
}

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

public void Do()
{
using var serviceC = _container.Resolve<ServiceC<Strategy>>(); // this cause the issue, please comment this line to resolve problem
// todo: @wip @fixme uncommenting causes to fail `Assert.AreEqual("value", serviceC.Strategy.ContextFromConstructor.Value)`
// because the serviceC.Strategy.ContextFromConstructor is null for some reason
// using var serviceC = _container.Resolve<ServiceC<Strategy>>(); // this cause the issue, please comment this line to resolve problem

_context.Value = "value";

Expand Down

0 comments on commit ecb97e9

Please sign in to comment.