public void Factory2()
        {
            _facility.AddTypedFactoryEntry(
                new FactoryEntry(
                    "protocolHandlerFactory", typeof(IProtocolHandlerFactory2), "Create", "Release"));

            _container.AddComponent("miranda", typeof(IProtocolHandler), typeof(MirandaProtocolHandler));
            _container.AddComponent("messenger", typeof(IProtocolHandler), typeof(MessengerProtocolHandler));

            IProtocolHandlerFactory2 factory =
                (IProtocolHandlerFactory2)_container["protocolHandlerFactory"];

            Assert.IsNotNull(factory);

            IProtocolHandler handler = factory.Create("miranda");

            Assert.IsNotNull(handler);
            Assert.IsTrue(handler is MirandaProtocolHandler);
            factory.Release(handler);

            handler = factory.Create("messenger");
            Assert.IsNotNull(handler);
            Assert.IsTrue(handler is MessengerProtocolHandler);
            factory.Release(handler);
        }
Esempio n. 2
0
        public void Factory2()
        {
            IProtocolHandlerFactory2 factory =
                (IProtocolHandlerFactory2)_container["protocolFac2"];

            Assert.IsNotNull(factory);

            IProtocolHandler handler = factory.Create("miranda");

            Assert.IsNotNull(handler);
            Assert.IsTrue(handler is MirandaProtocolHandler);
            factory.Release(handler);

            handler = factory.Create("messenger");
            Assert.IsNotNull(handler);
            Assert.IsTrue(handler is MessengerProtocolHandler);
            factory.Release(handler);
        }