Exemple #1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            Bus = BusInitializer.CreateBus("CustomerPortal_WebApp", x => { });
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            /**
             * Add mass transit to inject the mass transit classes we are going to use to handle
             * the messaging with the rabbiymq
             * Install-Package MassTransit.Extensions.DependencyInjection -Version 6.1.0
             * Install-Package MassTransit.RabbitMQ -Version 6.1.0
             *
             **/
            services.AddHealthChecks();
            services.AddMassTransit();

            //Whenever reference  IBusControl an instance will be injected
            // when you specify the queue name , when the message arrive to the exchange the binding will know to which queue it will be sent
            //rabbitmq://a-machine-name/a-virtual-host
            services.AddSingleton(provider => BusInitializer.CreateBus("rabbitmq://localhost", "", "MassTransitPubSubExample_queue_1", cfg => { /**nothing to be added to the configuration in here**/ }));

            //IBusControl :  IBus, IPublishEndpoint, IPublishObserverConnector, IPublishEndpointProvider, ISendEndpointProvider, ISendObserverConnector, IConsumePipeConnector, IRequestPipeConnector, IConsumeMessageObserverConnector, IConsumeObserverConnector, IReceiveObserverConnector, IReceiveEndpointObserverConnector, IReceiveConnector, IEndpointConfigurationObserverConnector, IProbeSite
            //IBus        :  is a logical endpoint contains (1 local endpoint - 0+ recieve endpoints)
            //IPublishEndpoint : let's the underlying transport know exactly which is the actual endpoint the message will be send to , (RabbitMQ , Azure Service Bus)
            //Whenever reference  IBus,IPublishEndpoint the same instance of IBusControl will be injected
            services.AddSingleton <IBus>(provider => provider.GetRequiredService <IBusControl>());
            services.AddSingleton <IPublishEndpoint>(provider => provider.GetRequiredService <IBusControl>());

            //BusService : if bus control will be managed by the us then we will use BusService to Start/Stop the bus
            //when un comment the app will keep loading without result
            //services.AddSingleton<IHostedService, BusService>();

            //whenever ref. the class inject an instance
            services.AddSingleton <MessageProducer, MessageProducer>();
        }
Exemple #3
0
 public static void Listen()
 {
     var bus = BusInitializer.CreateBus("Subscriber", x =>
     {
         x.Subscribe(subs =>
         {
             subs.Consumer <AdPriceChanged>().Permanent();
         });
     });
 }
Exemple #4
0
 private static void Main(string[] args)
 {
     using (
         BusInitializer.CreateBus("OrderSaga",
                                  x => x.Subscribe(c => c.Saga(new InMemorySagaRepository <OrderSaga>()).Permanent())))
     {
         Console.WriteLine("Waiting..");
         Console.ReadKey();
     }
 }
 public void Start()
 {
     _bus = BusInitializer.CreateBus("CustomerPortal_Backend", x =>
     {
         x.Subscribe(subs =>
         {
             subs.Consumer <TicketOpenedConsumer>().Permanent();
         });
     });
 }
Exemple #6
0
    static void Main(string[] args)
    {
      var bus = BusInitializer.CreateBus("TestSubscriber", x =>
      {
        x.Subscribe(subs =>
        {
          subs.Consumer<SomethingHappenedConsumer>().Permanent();
        });
      });

      Console.ReadKey();

      bus.Dispose();
    }
Exemple #7
0
        private static void Main(string[] args)
        {
            using (var bus = BusInitializer.CreateBus("OrderSender", x => { }))
            {
                var text = "";

                while (text != "quit")
                {
                    Console.Write("Enter an order: ");
                    text = Console.ReadLine();

                    var message = new Order {
                        What = text, When = DateTime.Now, CorrelationId = Guid.NewGuid()
                    };
                    var receiverUri = BusInitializer.GetUri("OrderSaga");

                    bus.GetEndpoint(receiverUri)
                    .Send(message);
                }
            }
        }
Exemple #8
0
        public static void RegisterServices(ContainerBuilder builder)
        {
            builder.RegisterType <UserSystemContext>().InstancePerRequest();
            //使用构造函数配置
            builder.Register(c => new CustomUserStore(c.Resolve <UserSystemContext>())).As <IUserStore <User> >().InstancePerRequest();
            //使用构造函数配置
            //  builder.Register(c => new CustomUserManager(c.Resolve<CustomUserStore>())).InstancePerLifetimeScope();

            builder.RegisterType <CustomUserManager>().UsingConstructor(typeof(IUserStore <User>)).InstancePerRequest();

            builder.RegisterType <UnitOfWork>().As <IUnitOfWork>().InstancePerRequest();

            builder.RegisterType <UserAppService>().As <IUserAppService>().InstancePerRequest();

            builder.RegisterType <UserRepository>().As <IUserRepository>().InstancePerRequest();

            builder.Register <IBusControl>(c => BusInitializer.CreateBus())
            .As <IBusControl>()
            .As <IPublishEndpoint>()
            .SingleInstance();
        }