public void RegisterTypeAfterRegisterInstanceDoesNotReusePreviousInstance() { var container = new QuickInjectContainer(); var foo = new Foo(); var foo2 = new Foo(); container.RegisterInstance<IFoo>(foo); var returnedInstance = container.Resolve<IFoo>(); var lifetime = new ContainerControlledLifetimeManager(); lifetime.SetValue(foo2); container.RegisterType<IFoo>(lifetime); var returnedInstance2 = container.Resolve<IFoo>(); Assert.AreNotSame(returnedInstance, returnedInstance2); }
public void FuncOfTTest() { var container = new QuickInjectContainer(); container.AddBuildPlanVisitor(new TransientLifetimeRemovalBuildPlanVisitor()); var lifetime = new ContainerControlledLifetimeManager(); var foo = new Foo(); lifetime.SetValue(foo); container.RegisterType<IFoo>(lifetime); var a = container.Resolve<Func<IFoo>>(); Assert.AreSame(a(), foo); }
public void LifetimeManagerWillProvideValueForAnInterfaceType() { var container = new QuickInjectContainer(); container.AddBuildPlanVisitor(new TransientLifetimeRemovalBuildPlanVisitor()); var lifetime = new ContainerControlledLifetimeManager(); var foo = new Foo(); lifetime.SetValue(foo); container.RegisterType<IFoo>(lifetime); var a = container.Resolve<IFoo>(); Assert.AreSame(a, foo); }
public void ComplicatedRegistrationsWithChildContainerLifetimes2() { var container = new QuickInjectContainer(); container.AddBuildPlanVisitor(new TransientLifetimeRemovalBuildPlanVisitor()); var child = container.CreateChildContainer(); var correctInstanceForIFooResolutionFromChild = new Foo(); var correctInstanceForFooResolutionFromChild = new SuperFoo(); var preSetFooOnLifetime = new Foo(); SuperFoo fooResolvedFromMainContainer = new SuperFoo(); var lifetime = new ContainerControlledLifetimeManager(); lifetime.SetValue(fooResolvedFromMainContainer); container.RegisterType<IFoo, Foo>(new ContainerControlledLifetimeManager(), new Microsoft.Practices.Unity.InjectionFactory(c => new Foo())); container.RegisterType<IBar, Foo>(new ContainerControlledLifetimeManager(), new Microsoft.Practices.Unity.InjectionFactory(c => correctInstanceForIFooResolutionFromChild)); container.RegisterType<Foo, SuperFoo>(new ContainerControlledLifetimeManager(), new Microsoft.Practices.Unity.InjectionFactory(c => fooResolvedFromMainContainer)); container.RegisterType<SuperFoo>(lifetime); child.RegisterType<Foo, SuperFoo>(new ContainerControlledLifetimeManager(), new Microsoft.Practices.Unity.InjectionFactory(c => correctInstanceForFooResolutionFromChild)); var f = container.Resolve<Foo>(); var g = container.Resolve<Foo>(); Assert.AreSame(child.Resolve<IBar>(), correctInstanceForIFooResolutionFromChild); Assert.AreSame(child.Resolve<IFoo>(), correctInstanceForIFooResolutionFromChild); Assert.AreSame(child.Resolve<Foo>(), correctInstanceForFooResolutionFromChild); Assert.AreSame(container.Resolve<Foo>(), fooResolvedFromMainContainer); Assert.AreSame(container.Resolve<SuperFoo>(), fooResolvedFromMainContainer); }