Exemple #1
0
        public void SetupLooksGood()
        {
            var container = new SimpleFactory.Container();

            container.Register <MyHandler>().Singleton();

            container.Register <MyGenericEventHandler>();

            IMessageAdapter adapter;

            adapter = new FakeAdapter(new List <object> {
                new SomethingHasHappend()
            });

            var Server = new MessageHandlerEngine(adapter,
                                                  null,
                                                  null
                                                  );

            Server.AttachMessageHandler <SomethingHasHappend, MyHandler>();
            Server.AttachGenericMessageHandler <MyGenericEventHandler>("#");


            adapter.StartAdapter();

            //System.Threading.Thread.Sleep(10000);

            adapter.StopAdapter();

            Assert.IsNotNull(container.CreateInstance <MyHandler>().input);
            Assert.AreEqual(1, container.CreateInstance <MyHandler>().Counter);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var container = new SimpleFactory.Container();
            var con       = new RabbitConnectionInfo
            {
                ClientName   = "Listner.Demo",
                ExchangeName = "Simployer",
                Server       = "localhost",
                UserName     = "******",
                Password     = "******",
                VirtualHost  = "/"
            };

            var pub = new PublishEventToRabbit(con, new Serializer());

            container.Register <PublishEventToRabbit>(() => pub).Singleton(); //This is singleton to hold the connection stuff for rabbit. Must be disposed
            container.Register <CustomPublisher>().Transient();               //This is the wrapper to capture the context of the current call
            container.Register <ApplicationContext>();                        // this is the actual context.. Very simplefied :)

            for (var x = 0; x < 10; x++)
            {
                var sender = container.CreateInstance <CustomPublisher>();
                sender.Publish(new SomethingOccured {
                    Message = $"This is message number{x}"
                });
            }

            pub.Dispose();
        }