コード例 #1
0
ファイル: Program.cs プロジェクト: bashocz/Examples
        static void Main(string[] args)
        {
            IWindsorContainer container = new WindsorContainer();
            container.AddFacility<TypedFactoryFacility>();

            container.Register(Component.For<IDummyComponent>().ImplementedBy<DummyComponent>().Named("Action").LifeStyle.Transient);
            container.Register(Component.For<IDummyComponentFactory>().AsFactory().LifeStyle.Transient);

            IDummyComponentFactory factory = container.Resolve<IDummyComponentFactory>();

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("{0:N0} bytes used at the start", GC.GetTotalMemory(true));

                IDummyComponent[] array = new IDummyComponent[10];
                for (int j = 0; j < array.Length; j++)
                    array[j] = factory.GetAction();

                Console.WriteLine("{0:N0} bytes used at the mezivysledek", GC.GetTotalMemory(true));

                for (int j = 0; j < array.Length; j++)
                {
                    factory.Release(array[j]);
                    array[j] = null;
                }

                Console.WriteLine("{0:N0} bytes used at the end", GC.GetTotalMemory(true));
            }
        }
コード例 #2
0
        public void Factory3()
        {
            IComponentFactory1 factory =
                (IComponentFactory1)_container["compFactory1"];

            Assert.IsNotNull(factory);

            IDummyComponent comp1 = factory.Construct();

            Assert.IsNotNull(comp1);

            IDummyComponent comp2 = factory.Construct();

            Assert.IsNotNull(comp2);
        }
コード例 #3
0
        public void Factory4()
        {
            IComponentFactory2 factory =
                (IComponentFactory2)_container["compFactory2"];

            Assert.IsNotNull(factory);

            IDummyComponent comp1 = (IDummyComponent)factory.Construct("comp1");

            Assert.IsTrue(comp1 is Component1);
            Assert.IsNotNull(comp1);

            IDummyComponent comp2 = (IDummyComponent)factory.Construct("comp2");

            Assert.IsTrue(comp2 is Component2);
            Assert.IsNotNull(comp2);
        }
コード例 #4
0
        public void Factory3()
        {
            _facility.AddTypedFactoryEntry(
                new FactoryEntry(
                    "compFactory", typeof(IComponentFactory1), "Construct", ""));

            _container.AddComponent("comp1", typeof(IDummyComponent), typeof(Component1));
            _container.AddComponent("comp2", typeof(IDummyComponent), typeof(Component2));

            IComponentFactory1 factory =
                (IComponentFactory1)_container["compFactory"];

            Assert.IsNotNull(factory);

            IDummyComponent comp1 = factory.Construct();

            Assert.IsNotNull(comp1);

            IDummyComponent comp2 = factory.Construct();

            Assert.IsNotNull(comp2);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: bashocz/Examples
 public Component2Log(IDummyComponent component)
 {
     _component = component;
     _guid = Guid.NewGuid();
 }