Пример #1
0
        public void ParametersAndServicesBestCase()
        {
            var store = new DefaultConfigurationStore();

            var config     = new MutableConfiguration("component");
            var parameters = new MutableConfiguration("parameters");

            config.Children.Add(parameters);
            parameters.Children.Add(new MutableConfiguration("name", "hammett"));
            parameters.Children.Add(new MutableConfiguration("port", "120"));

            store.AddComponentConfiguration("service", config);

            Kernel.ConfigurationStore = store;

            Container.Register(Component.For <A>().Named("a"),
                               Component.For <ServiceUser2>().Named("service"));

            var service = Container.Resolve <ServiceUser2>("service");

            Assert.IsNotNull(service);
            Assert.IsNotNull(service.AComponent);
            Assert.IsNull(service.BComponent);
            Assert.IsNull(service.CComponent);
            Assert.AreEqual("hammett", service.Name);
            Assert.AreEqual(120, service.Port);
        }
        public void OperationsLocked()
        {
            IConfigurationStore configurationStore = new DefaultConfigurationStore();

            MutableConfiguration facNode = new MutableConfiguration("facility");

            facNode.Attributes["id"]   = "slow";
            facNode.Attributes["type"] = "Castle.Windsor.Tests.Facilities.SlowlyInitFacility, Castle.Windsor.Tests";

            configurationStore.AddFacilityConfiguration("slow", facNode);

            MutableConfiguration compNode = new MutableConfiguration("component");

            compNode.Attributes["id"]   = "a";
            compNode.Attributes["type"] = "Castle.Windsor.Tests.Components.CalculatorService, Castle.Windsor.Tests";

            configurationStore.AddComponentConfiguration("a", compNode);

            AsyncInitializationContainer container = new AsyncInitializationContainer(configurationStore);

            Assert.AreEqual(1, container.Kernel.GraphNodes.Length);
            Assert.AreEqual(1, container.Kernel.GraphNodes.Length);

            CalculatorService service = (CalculatorService)
                                        container[typeof(CalculatorService)];

            Assert.IsNotNull(service);
            service = (CalculatorService)
                      container[typeof(CalculatorService)];
        }
        public void ParametersAndServicesBestCase2()
        {
            DefaultConfigurationStore store = new DefaultConfigurationStore();

            MutableConfiguration config     = new MutableConfiguration("component");
            MutableConfiguration parameters = (MutableConfiguration)
                                              config.Children.Add(new MutableConfiguration("parameters"));

            parameters.Children.Add(new MutableConfiguration("name", "hammett"));
            parameters.Children.Add(new MutableConfiguration("port", "120"));
            parameters.Children.Add(new MutableConfiguration("Scheduleinterval", "22"));

            store.AddComponentConfiguration("service", config);

            kernel.ConfigurationStore = store;

            kernel.AddComponent("a", typeof(A));
            kernel.AddComponent("service", typeof(ServiceUser2));

            ServiceUser2 service = (ServiceUser2)kernel["service"];

            Assert.IsNotNull(service);
            Assert.IsNotNull(service.AComponent);
            Assert.IsNull(service.BComponent);
            Assert.IsNull(service.CComponent);
            Assert.AreEqual("hammett", service.Name);
            Assert.AreEqual(120, service.Port);
            Assert.AreEqual(22, service.ScheduleInterval);
        }