Exemplo n.º 1
0
        public void ResolveSingletonWithDependencies()
        {
            var container = new IocBuilder()
                            .Register <IA, A>()
                            .Register <IB, B>()
                            .Register <IC, C>()
                            .RegisterSingleton <ID, D>()
                            .Build();

            var d1 = container.Resolve <ID>();
            var d2 = container.Resolve <ID>();

            Assert.AreEqual(d1, d2);
        }
Exemplo n.º 2
0
        public void ScopeResolvesAndDisposesLambdaCorrectly()
        {
            var container = new IocBuilder()
                            .Register <IA, A>()
                            .RegisterPerScope <IB>(c => new B())
                            .Build();

            IA a1 = null;
            IA a2 = null;
            IB b1 = null;
            IB b2 = null;

            using (var scope = container.Scope)
            {
                a1 = scope.Resolve <IA>();
                a2 = scope.Resolve <IA>();
                b1 = scope.Resolve <IB>();
                b2 = scope.Resolve <IB>();
            }

            Assert.AreNotEqual(a1, a2);
            Assert.AreEqual(b1, b2);

            b1 = container.Resolve <IB>();

            Assert.AreNotEqual(b1, b2);
        }