public void ShouldReturnSameValueWithinSameExplicitScope() { var sut = new NSubContainer(); sut.Register <ITestInterface, TestImplSingleCtor>(NSubLifetime.PerScope); sut.Register <ClassWithDependency, ClassWithDependency>(NSubLifetime.Transient); var scope = sut.CreateScope(); var result1 = scope.Resolve <ClassWithDependency>(); var result2 = scope.Resolve <ClassWithDependency>(); Assert.That(result1, Is.Not.SameAs(result2)); Assert.That(result1.Dep, Is.SameAs(result2.Dep)); }
public void ShouldUseSameLifetimeForDecorator_PerScopeCase() { var sut = new NSubContainer(); sut.Register <ITestInterface, TestImplSingleCtor>(NSubLifetime.PerScope); sut.Decorate <ITestInterface>((impl, r) => new TestImplDecorator(impl)); var scope = sut.CreateScope(); var result1 = scope.Resolve <ITestInterface>(); var result2 = scope.Resolve <ITestInterface>(); Assert.That(result1, Is.SameAs(result2)); Assert.That(((TestImplDecorator)result1).Inner, Is.SameAs(((TestImplDecorator)result2).Inner)); }