Example #1
0
        public void SameOuterShareSameInnerForResolutionScope()
        {
            var container = new Container();

            container.Register <IInner, Inner>(Reuse.InResolutionScopeOf <IOuter>());
            container.Register <IOuter, Outer>(Reuse.Singleton);

            var outer1 = container.Resolve <IOuter>();
            var outer2 = container.Resolve <IOuter>();

            Assert.Same(outer1, outer2);
            Assert.Same(outer1.Inner, outer2.Inner);
        }
Example #2
0
        public void DifferentOuterHaveDifferentInnerForResolutionScope()
        {
            var container = new Container();

            container.Register <IInner, Inner>(Reuse.InResolutionScopeOf <IOuter>());
            container.Register <IOuter, Outer>(Reuse.Transient);

            var outer1 = container.Resolve <IOuter>();
            var outer2 = container.Resolve <IOuter>();

            Assert.NotSame(outer1, outer2);
            Assert.NotSame(outer1.Inner, outer2.Inner);
        }