public void SimpleUsage() { IKernel kernel = new DefaultKernel(); kernel.AddComponent("a", typeof(PoolableComponent1)); PoolableComponent1 inst1 = kernel["a"] as PoolableComponent1; PoolableComponent1 inst2 = kernel["a"] as PoolableComponent1; Assert.IsNotNull(inst1); Assert.IsNotNull(inst2); kernel.ReleaseComponent(inst2); kernel.ReleaseComponent(inst1); PoolableComponent1 other1 = kernel["a"] as PoolableComponent1; PoolableComponent1 other2 = kernel["a"] as PoolableComponent1; Assert.IsNotNull(other1); Assert.IsNotNull(other2); Assert.AreSame(inst1, other1); Assert.AreSame(inst2, other2); kernel.ReleaseComponent(inst2); kernel.ReleaseComponent(inst1); }
public void MaxSize() { IKernel kernel = new DefaultKernel(); kernel.AddComponent("a", typeof(PoolableComponent1)); ArrayList instances = new ArrayList(); instances.Add(kernel["a"] as PoolableComponent1); instances.Add(kernel["a"] as PoolableComponent1); instances.Add(kernel["a"] as PoolableComponent1); instances.Add(kernel["a"] as PoolableComponent1); instances.Add(kernel["a"] as PoolableComponent1); PoolableComponent1 other1 = kernel["a"] as PoolableComponent1; Assert.IsNotNull(other1); Assert.IsTrue(!instances.Contains(other1)); foreach(object inst in instances) { kernel.ReleaseComponent(inst); } kernel.ReleaseComponent(other1); PoolableComponent1 other2 = kernel["a"] as PoolableComponent1; Assert.IsNotNull(other2); Assert.IsTrue(other1 != other2); Assert.IsTrue(instances.Contains(other2)); kernel.ReleaseComponent(other2); }
public void MaxSize() { IKernel kernel = new DefaultKernel(); kernel.AddComponent("a", typeof(PoolableComponent1)); ArrayList instances = new ArrayList(); instances.Add(kernel["a"] as PoolableComponent1); instances.Add(kernel["a"] as PoolableComponent1); instances.Add(kernel["a"] as PoolableComponent1); instances.Add(kernel["a"] as PoolableComponent1); instances.Add(kernel["a"] as PoolableComponent1); PoolableComponent1 other1 = kernel["a"] as PoolableComponent1; Assert.IsNotNull(other1); Assert.IsTrue(!instances.Contains(other1)); foreach (object inst in instances) { kernel.ReleaseComponent(inst); } kernel.ReleaseComponent(other1); PoolableComponent1 other2 = kernel["a"] as PoolableComponent1; Assert.IsNotNull(other2); Assert.IsTrue(other1 != other2); Assert.IsTrue(instances.Contains(other2)); kernel.ReleaseComponent(other2); }
public void MaxSize() { IKernel kernel = new DefaultKernel(); kernel.Register(Component.For(typeof(PoolableComponent1)).Named("a")); var instances = new List<PoolableComponent1> { kernel.Resolve<PoolableComponent1>("a"), kernel.Resolve<PoolableComponent1>("a"), kernel.Resolve<PoolableComponent1>("a"), kernel.Resolve<PoolableComponent1>("a"), kernel.Resolve<PoolableComponent1>("a") }; PoolableComponent1 other1 = kernel.Resolve<PoolableComponent1>("a"); Assert.IsNotNull(other1); Assert.IsTrue(!instances.Contains(other1)); foreach (PoolableComponent1 inst in instances) { kernel.ReleaseComponent(inst); } kernel.ReleaseComponent(other1); PoolableComponent1 other2 = kernel.Resolve<PoolableComponent1>("a"); Assert.IsNotNull(other2); Assert.IsTrue(other1 != other2); Assert.IsTrue(instances.Contains(other2)); kernel.ReleaseComponent(other2); }
public void SimpleUsage() { IKernel kernel = new DefaultKernel(); kernel.Register(Component.For(typeof(PoolableComponent1)).Named("a")); PoolableComponent1 inst1 = kernel.Resolve<PoolableComponent1>("a"); PoolableComponent1 inst2 = kernel.Resolve<PoolableComponent1>("a"); Assert.IsNotNull(inst1); Assert.IsNotNull(inst2); kernel.ReleaseComponent(inst2); kernel.ReleaseComponent(inst1); PoolableComponent1 other1 = kernel.Resolve<PoolableComponent1>("a"); PoolableComponent1 other2 = kernel.Resolve<PoolableComponent1>("a"); Assert.IsNotNull(other1); Assert.IsNotNull(other2); Assert.AreSame(inst1, other1); Assert.AreSame(inst2, other2); kernel.ReleaseComponent(inst2); kernel.ReleaseComponent(inst1); }
public void SetUp() { kernel = new DefaultKernel(); kernel.AddFacility <StartableFacility>(); kernel.Register( Component.For <StartableDisposableAndInitializableComponent>() .LifeStyle.Transient ); component = kernel.Resolve <StartableDisposableAndInitializableComponent>(); component.DoSomething(); kernel.ReleaseComponent(component); calledMethods = component.calledMethods; }
public void TestInterfaceBasedStartable() { IKernel kernel = new DefaultKernel(); kernel.AddFacility("startable", new StartableFacility()); kernel.AddComponent("a", typeof(StartableComponent)); StartableComponent component = kernel["a"] as StartableComponent; Assert.IsNotNull(component); Assert.IsTrue(component.Started); Assert.IsFalse(component.Stopped); kernel.ReleaseComponent(component); Assert.IsTrue(component.Stopped); }
public void TestComponentWithNoInterface() { IKernel kernel = new DefaultKernel(); MutableConfiguration compNode = new MutableConfiguration("component"); compNode.Attributes["id"] = "b"; compNode.Attributes["startable"] = "true"; compNode.Attributes["startMethod"] = "Start"; compNode.Attributes["stopMethod"] = "Stop"; kernel.ConfigurationStore.AddComponentConfiguration("b", compNode); kernel.AddFacility("startable", new StartableFacility()); kernel.AddComponent("b", typeof(NoInterfaceStartableComponent)); NoInterfaceStartableComponent component = kernel["b"] as NoInterfaceStartableComponent; Assert.IsNotNull(component); Assert.IsTrue(component.Started); Assert.IsFalse(component.Stopped); kernel.ReleaseComponent(component); Assert.IsTrue(component.Stopped); }