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(); }
public CustomPublisher(PublishEventToRabbit toRabbit, ApplicationContext context) { this.context = context; this.toRabbit = toRabbit; }