Ejemplo n.º 1
0
        public void ResolveMultipelWithScope()
        {
            var builder = new IocBuilder();

            builder.RegisterSingleton <IA, A>();
            builder.Register <IB, B>();
            builder.Register <IC, C>();
            builder.Register <ID, D>();
            builder.Register <ID, D>();
            builder.RegisterPerScope <ID, D>();


            builder.Register <IF, F>();
            var container = builder.Build();

            IEnumerable <ID> d1;

            using (var scope = container.Scope)
            {
                d1 = scope.Resolve <IEnumerable <ID> >();
                var d2 = scope.Resolve <IEnumerable <ID> >();
                //Assert.AreNotEqual(d1.FirstOrDefault().GetHashCode(), d2.LastOrDefault().GetHashCode());
                Assert.AreEqual(d1.LastOrDefault(), d2.LastOrDefault());
            }
            var d3 = container.Resolve <IEnumerable <ID> >();

            Assert.AreNotEqual(d1.FirstOrDefault(), d3.LastOrDefault());
            Assert.AreNotEqual(d1.LastOrDefault(), d3.LastOrDefault());
        }