static void Main(string[] args) { try { // Wire up the payment queue to use mainContainer var paymentQueue = new PaymentQueue( Configure .With(new CastleWindsorContainerAdapter(CreateContainer())) .Transport(t => t.UseSqlServerAsOneWayClient("server=.;database=Scratch;trusted_connection=true")) .Routing(r => r.TypeBased().Map <Payment>("PaymentQueue")) .Start() ); // Need another container for the orders queue var orderQueue = new OrderQueue( Configure .With(new CastleWindsorContainerAdapter(CreateContainer())) .Transport(t => t.UseRabbitMqAsOneWayClient("amqp://localhost")) .Routing(r => r.TypeBased().Map <Order>("OrderQueue")) .Start() ); var mainContainer = CreateContainer(); mainContainer.Register(Component.For <PaymentQueue>().Instance(paymentQueue), Component.For <OrderQueue>().Instance(orderQueue)); var bus = Configure .With(new CastleWindsorContainerAdapter(mainContainer)) .Logging(l => l.ColoredConsole()) .Transport(t => t.UseSqlServer("server=.;database=Scratch;trusted_connection=true", "PaymentQueue")) .Options(o => { o.SimpleRetryStrategy(errorQueueAddress: "PaymentQueue-error"); o.SetMaxParallelism(1); o.SetNumberOfWorkers(1); }) .Start(); while (true) { var input = Console.ReadLine(); if (input == "q") { bus.Dispose(); break; } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
protected void Application_Start() { // Main container first var mainContainer = CreateContainer(); // Hook the main container into the web api dependency resolver var dependencyResolver = new WindsorDependencyResolver(mainContainer); var configuration = GlobalConfiguration.Configuration; configuration.DependencyResolver = dependencyResolver; ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(mainContainer.Kernel)); // Wire up the payment queue to use mainContainer var paymentQueue = new PaymentQueue( Configure .With(new CastleWindsorContainerAdapter(CreateContainer())) .Transport(t => t.UseSqlServerAsOneWayClient("server=.;database=Scratch;trusted_connection=true")) .Routing(r => r.TypeBased().Map <Payment>("PaymentQueue")) .Start() ); // Need another container for the orders queue var orderQueue = new OrderQueue( Configure .With(new CastleWindsorContainerAdapter(CreateContainer())) .Transport(t => t.UseRabbitMqAsOneWayClient("amqp://localhost")) .Routing(r => r.TypeBased().Map <Order>("OrderQueue")) .Start() ); // Register our custom queues in every container... not sure this is going to work, should foreach (var container in _containers) { container.Register( Component.For <PaymentQueue>().Instance(paymentQueue), Component.For <OrderQueue>().Instance(orderQueue) ); } GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes); }
public PaymentsService(IPaymentsRepository repo, PaymentQueue queue) { _repo = repo; _queue = queue; }