Created
March 19, 2012 07:22
-
-
Save andreasohlund/2100650 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| [Fact] | |
| public void NSBTest() | |
| { | |
| this.kernel.Bind<Foo>().ToSelf().InTransientScope(); | |
| this.kernel.Bind<Foo>().ToSelf().WhenAnyAnchestorNamed("Container").InNamedScope("Container"); | |
| this.kernel.Bind<ChildContainer>().ToSelf().Named("Container").DefinesNamedScope("Container"); | |
| var instance1 = this.kernel.Get<Foo>(); | |
| instance1.Should().NotBeNull(); | |
| var instance2 = this.kernel.Get<Foo>(); | |
| instance2.Should().NotBeNull(); | |
| instance2.Should().NotBeSameAs(instance1); | |
| var childContainer = this.kernel.Get<ChildContainer>(); | |
| var childInstance1 = childContainer.Get<Foo>(); | |
| childInstance1.Should().NotBeNull(); | |
| childInstance1.Should().NotBeSameAs(instance1); | |
| childInstance1.Should().NotBeSameAs(instance2); | |
| var childInstance2 = childContainer.Get<Foo>(); | |
| childInstance2.Should().NotBeNull(); | |
| childInstance2.Should().NotBeSameAs(instance1); | |
| childInstance2.Should().NotBeSameAs(instance2); | |
| childInstance2.Should().BeSameAs(childInstance1); | |
| childInstance1.IsDisposed.Should().BeFalse(); | |
| childInstance2.IsDisposed.Should().BeFalse(); | |
| childContainer.Dispose(); | |
| childInstance1.IsDisposed.Should().BeTrue(); | |
| childInstance2.IsDisposed.Should().BeTrue(); | |
| } | |
| public class ChildContainer : DisposeNotifyingObject, IResolutionRoot | |
| { | |
| private readonly IResolutionRoot resolutionRoot; | |
| public ChildContainer(IResolutionRoot resolutionRoot) | |
| { | |
| this.resolutionRoot = resolutionRoot; | |
| } | |
| public bool CanResolve(IRequest request) | |
| { | |
| return this.resolutionRoot.CanResolve(request); | |
| } | |
| public bool CanResolve(IRequest request, bool ignoreImplicitBindings) | |
| { | |
| return this.resolutionRoot.CanResolve(request, ignoreImplicitBindings); | |
| } | |
| public IEnumerable<object> Resolve(IRequest request) | |
| { | |
| return this.resolutionRoot.Resolve(request); | |
| } | |
| public IRequest CreateRequest(Type service, Func<IBindingMetadata, bool> constraint, IEnumerable<IParameter> parameters, bool isOptional, bool isUnique) | |
| { | |
| return this.resolutionRoot.CreateRequest(service, constraint, parameters, isOptional, isUnique); | |
| } | |
| } | |
| public class Foo : IDisposable | |
| { | |
| public void Dispose() | |
| { | |
| this.IsDisposed = true; | |
| } | |
| public bool IsDisposed { get; private set; } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment