Skip to content

Commit 35c06f6

Browse files
author
maximv
committed
fixed: #316
1 parent 8892117 commit 35c06f6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/DryIoc/Container.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4737,7 +4737,7 @@ internal static bool TryGetUsedInstance(this IResolverContext r, Type serviceTyp
47374737
// todo: @perf no need to check for IDisposable in TrackDisposable
47384738
/// <summary>A bit if sugar to track disposable in the current scope or in the singleton scope as a fallback</summary>
47394739
public static T TrackDisposable<T>(this IResolverContext r, T instance) where T : IDisposable =>
4740-
(T)(r.SingletonScope ?? r.CurrentScope).TrackDisposable(instance); // todo: @fix check the scope first
4740+
(T)(r.CurrentScope ?? r.SingletonScope).TrackDisposable(instance);
47414741
}
47424742

47434743
/// <summary>The result delegate generated by DryIoc for service creation.</summary>

test/DryIoc.UnitTests/ReuseTests.cs

+13
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,19 @@ public void Disposing_container_should_dispose_the_registered_instance_even_not_
558558
Assert.IsTrue(service.IsDisposed);
559559
}
560560

561+
[Test]
562+
public void Disposing_the_scope_should_dispose_the_registered_instance_even_not_resolved()
563+
{
564+
var container = new Container();
565+
var service = new SomethingDisposable();
566+
using (var scope = container.OpenScope())
567+
{
568+
scope.Use(scope.TrackDisposable(service));
569+
}
570+
571+
Assert.IsTrue(service.IsDisposed);
572+
}
573+
561574
[Test]
562575
public void Dispose_should_happen_in_reverse_resolution_order()
563576
{

0 commit comments

Comments
 (0)