forked from ninject/Ninject
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: When an object that is the scope of another object is release…
…d an Exception was thrown.
- Loading branch information
Showing
4 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
namespace Ninject.Tests.Integration | ||
{ | ||
using System; | ||
|
||
using FluentAssertions; | ||
|
||
using Xunit; | ||
|
||
public class WhenReleasingAnObject | ||
{ | ||
private Foo foo; | ||
|
||
private StandardKernel kernel; | ||
|
||
public WhenReleasingAnObject() | ||
{ | ||
this.kernel = new StandardKernel(); | ||
|
||
this.kernel.Bind<Foo>().ToSelf().InSingletonScope(); | ||
this.kernel.Bind<Bar>().ToSelf().InScope(ctx => this.foo); | ||
|
||
this.foo = this.kernel.Get<Foo>(); | ||
} | ||
|
||
[Fact] | ||
public void ItIsDisposed() | ||
{ | ||
this.kernel.Release(this.foo); | ||
|
||
this.foo.Disposed.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void ObjectsThatHaveItAsScopeAreDisposed() | ||
{ | ||
var bar = kernel.Get<Bar>(); | ||
|
||
this.kernel.Release(this.foo); | ||
|
||
bar.Disposed.Should().BeTrue(); | ||
} | ||
|
||
public class Foo : IDisposable | ||
{ | ||
public void Dispose() | ||
{ | ||
this.Disposed = true; | ||
} | ||
|
||
public bool Disposed { get; set; } | ||
} | ||
|
||
public class Bar : IDisposable | ||
{ | ||
public void Dispose() | ||
{ | ||
this.Disposed = true; | ||
} | ||
|
||
public bool Disposed { get; set; } | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters