public void TestResolveWithName() { IUnityContainer uc = new UnityContainer(); UnityTestClass obj = uc.Resolve <UnityTestClass>("Hello"); Assert.IsNotNull(obj); }
public void RegisterWithParentAndChild() { //create unity container IUnityContainer parentuc = new UnityContainer(); //register type UnityTestClass parentuc.RegisterType <UnityTestClass>(new ContainerControlledLifetimeManager()); UnityTestClass mytestparent = parentuc.Resolve <UnityTestClass>(); mytestparent.Name = "Hello World"; IUnityContainer childuc = parentuc.CreateChildContainer(); childuc.RegisterType <UnityTestClass>(new ContainerControlledLifetimeManager()); UnityTestClass mytestchild = childuc.Resolve <UnityTestClass>(); Assert.AreNotSame(mytestparent.Name, mytestchild.Name); }
public void UseContainerControlledLifetime() { UnityTestClass obj1 = new UnityTestClass(); obj1.Name = "InstanceObj"; UnityContainer parentuc = new UnityContainer(); parentuc.RegisterType <UnityTestClass>(new ContainerControlledLifetimeManager()); UnityTestClass parentinstance = parentuc.Resolve <UnityTestClass>(); parentinstance.Name = "Hello World Ob1"; parentinstance = null; GC.Collect(); UnityTestClass parentinstance1 = parentuc.Resolve <UnityTestClass>(); Assert.AreSame("Hello World Ob1", parentinstance1.Name); }