public void TestComponentWithNoInterface()
		{
			IKernel kernel = new DefaultKernel();
			kernel.ComponentCreated += new ComponentInstanceDelegate(OnNoInterfaceStartableComponentStarted);

			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.Register(Component.For(typeof(NoInterfaceStartableComponent)).Named("b"));

			Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");

			NoInterfaceStartableComponent component = kernel["b"] as NoInterfaceStartableComponent;

			Assert.IsNotNull(component);
			Assert.IsTrue(component.Started);
			Assert.IsFalse(component.Stopped);

			kernel.ReleaseComponent(component);
			Assert.IsTrue(component.Stopped);
		}
Beispiel #2
0
		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.ComponentCreated += new ComponentInstanceDelegate(OnStartableComponentStarted);

			kernel.AddFacility("startable", new StartableFacility());

			kernel.Register(Component.For(typeof(StartableComponent)).Named("a"));

			Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");

			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 TestStartableWithRegisteredCustomDependencies()
		{
			IKernel kernel = new DefaultKernel();
			kernel.ComponentCreated += new ComponentInstanceDelegate(OnStartableComponentStarted);

			kernel.AddFacility("startable", new StartableFacility());

			var dependencies = new Dictionary<string, object> { { "config", 1 } };
			kernel.Register(Component.For(typeof(StartableComponentCustomDependencies)).Named("a"));
			kernel.RegisterCustomDependencies(typeof(StartableComponentCustomDependencies), dependencies);

			Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");

			StartableComponentCustomDependencies component = kernel["a"] as StartableComponentCustomDependencies;

			Assert.IsNotNull(component);
			Assert.IsTrue(component.Started);
			Assert.IsFalse(component.Stopped);

			kernel.ReleaseComponent(component);
			Assert.IsTrue(component.Stopped);
		}
		public void TestStartableCustomDependencies()
		{
			IKernel kernel = new DefaultKernel();
			kernel.ComponentCreated += new ComponentInstanceDelegate(OnStartableComponentStarted);

			kernel.AddFacility("startable", new StartableFacility());

			kernel.Register(
				Component.For<StartableComponentCustomDependencies>()
					.Named("a")
					.DependsOn(Property.ForKey("config").Eq(1))
				);
			Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");

			StartableComponentCustomDependencies component = kernel["a"] as StartableComponentCustomDependencies;

			Assert.IsNotNull(component);
			Assert.IsTrue(component.Started);
			Assert.IsFalse(component.Stopped);

			kernel.ReleaseComponent(component);
			Assert.IsTrue(component.Stopped);
		}
		public void TestStartableWithRegisteredCustomDependencies()
		{
			IKernel kernel = new DefaultKernel();
			kernel.ComponentCreated += new ComponentInstanceDelegate(OnStartableComponentStarted);

			kernel.AddFacility("startable", new StartableFacility());

			Hashtable dependencies = new Hashtable();
			dependencies.Add("config", 1);
			kernel.AddComponent("a", typeof(StartableComponentCustomDependencies));
			kernel.RegisterCustomDependencies(typeof(StartableComponentCustomDependencies), dependencies);

			Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");

			StartableComponentCustomDependencies component = kernel["a"] as StartableComponentCustomDependencies;

			Assert.IsNotNull(component);
			Assert.IsTrue(component.Started);
			Assert.IsFalse(component.Stopped);

			kernel.ReleaseComponent(component);
			Assert.IsTrue(component.Stopped);
		}
		public void TestStartableComponentWithServiceDependency()
		{
			IKernel kernel = new DefaultKernel();
			kernel.ComponentModelBuilder.AddContributor(new ServiceDependencyComponentInspector());
			kernel.ComponentCreated += new ComponentInstanceDelegate(OnStartableComponentWithServiceDependencyStarted);

			kernel.AddFacility("startable", new StartableFacility());

			kernel.Register(Component.For<StartableComponentWithServiceDependency>());

			Assert.IsFalse(startableCreatedBeforeResolved, "Component was started before dependency was registered");

			kernel.Register(Component.For<ServiceDependency>());

			Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");

			StartableComponentWithServiceDependency component = kernel.Resolve<StartableComponentWithServiceDependency>();

			Assert.IsNotNull(component);
			Assert.IsTrue(component.Started);
			Assert.IsFalse(component.Stopped);

			kernel.ReleaseComponent(component);
			Assert.IsTrue(component.Stopped);
		}