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); }
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(); }
static void Main(string[] args) { //Use any container.. var container = new SimpleFactory.Container(); container.Register <MyHandler>().Scoped(); //Connectioninfo to the rabbit server. //The ClientName is important, as it is used in the infrastructure to indentify the host. RabbitConnectionInfo connectionInfo = new RabbitConnectionInfo { UserName = "******", Password = "******", Server = "localhost", ExchangeName = "Simployer", ClientName = "MyTestingApp" }; //Create the RabbitAdapter. This is a spesific implementation for Rabbit. //IMessageAdapter messageAdapter = new RabbitMessageAdapter( // connectionInfo, // //The serializer that will be used by the adapter. This must implement the ISerializer from Itas.Infrastructure. // new Serializer(), // //This Func<BasicDeliveryEventArgs> gives you the chance to create a context value for your eventhandler. // //Setting the ClientContext e.g // (sp, eventArgs, data) => { } // ); //Then instanciate the MessageHandler.. Passing in the Adapter. //var server = new MessageHandlerEngine( // messageAdapter, // //This Func<Type,object> is used instead of taking a dependency on a Container. // //Here you can create your scope to for your context // () => new SimpleFactory.SimplefactoryProvider(container)); ////Register a typed handler for the Engine. ////The engine will ask for an instance of MessageHandle<MyEventClass> using the above Action<Type,object>. //server.AttachMessageHandler<SomethingOccured, MyHandler>(); //Registering an untyped handler. //Will ask for an instance of the type mapped against this bindingkey. //server.AttachGenericMessageHandler<GenericEventHandler>("#"); //Start the server. //The infrastructure will be created on the rabbit server and the adapter will start to recieve the messages. //server.StartServer(); Console.ReadLine(); //Stop the server to dispose the connections to Rabbit. //server.StopServer(); }