public void ResolutionFailsWithNoRegistrations()
 {
     using (var resolver = new Resolver())
     {
         using (var child = resolver.CreateChild())
         {
             Assert.Throws <NoImplementationSpecifiedForInterfaceException>(() => { child.Resolve(typeof(TestCases.IService2)); });
         }
     }
 }
Пример #2
0
        public void DoesDisposeChildren()
        {
            IResolver parent, child;

            using (parent = new Resolver())
            {
                child = parent.CreateChild();
            }
            Assert.Throws <InvalidOperationException>(() => { child.Resolve(typeof(TestCases.ImplementationOfIService2)); });
        }
Пример #3
0
 public void DisposingChildDoesNotDisposeParent()
 {
     using (var resolver = new Resolver())
     {
         using (var child = resolver.CreateChild())
         {
             child.Register(typeof(TestCases.IService2), typeof(TestCases.ImplementationOfIService2));
         }
         resolver.Register(typeof(TestCases.IService2), typeof(TestCases.AlternativeImplementationOfIService2));
     }
 }
 public void ChildDefersToParent()
 {
     using (var resolver = new Resolver())
     {
         resolver.Register(typeof(TestCases.IService2), typeof(TestCases.ImplementationOfIService2));
         using (var child = resolver.CreateChild())
         {
             var value = child.Resolve(typeof(TestCases.IService2));
             Assert.Equal(typeof(TestCases.ImplementationOfIService2), value.GetType());
         }
     }
 }
 public void ChildLifetimeOverridesParent()
 {
     using (var resolver = new Resolver())
     {
         resolver.Register(typeof(TestCases.IService2), typeof(TestCases.ImplementationOfIService2), Lifetime.Transient);
         using (var child = resolver.CreateChild())
         {
             child.Register(typeof(TestCases.IService2), typeof(TestCases.AlternativeImplementationOfIService2), Lifetime.Singleton);
             var value1 = child.Resolve(typeof(TestCases.IService2));
             var value2 = child.Resolve(typeof(TestCases.IService2));
             Assert.Equal(value1, value2);
         }
     }
 }
        public IDependencyScope BeginScope()
        {
            var childContainer = Resolver.CreateChild();

            return(new IocDependencyScope(childContainer));
        }