예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddMassTransit(cfg =>
            {
                cfg.AddConsumer <OrderCardNumberValidateConsumer>();

                cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider, (cfg, host) =>
                {
                    cfg.UseHealthCheck(provider);
                    //cfg.ReceiveEndpoint(BusConstants.OrderQueue, ep =>
                    //{
                    //    ep.ConfigureConsumer<OrderCardNumberValidateConsumer>(provider);
                    //});
                }));
            });

            services.AddMassTransitHostedService();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Card_ms", Version = "v1"
                });
            });
        }
        static async Task Main(string[] args)
        {
            string connectionString = "Server=NAG6CHANDRVAR01;Database=OrderDb;Trusted_Connection=True;";

            var builder = new HostBuilder()
                          .ConfigureServices((hostContext, services) =>
            {
                services.AddMassTransit(cfg =>
                {
                    cfg.AddSagaStateMachine <OrderStateMachine, OrderStateData>()

                    .EntityFrameworkRepository(r =>
                    {
                        r.ConcurrencyMode = ConcurrencyMode.Pessimistic;     // or use Optimistic, which requires RowVersion

                        r.AddDbContext <DbContext, OrderStateDbContext>((provider, builder) =>
                        {
                            builder.UseSqlServer(connectionString, m =>
                            {
                                m.MigrationsAssembly(Assembly.GetExecutingAssembly().GetName().Name);
                                m.MigrationsHistoryTable($"__{nameof(OrderStateDbContext)}");
                            });
                        });
                    });

                    cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider));
                });

                services.AddMassTransitHostedService();
            });

            await builder.RunConsoleAsync();
        }
예제 #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAutoMapper(typeof(MappingProfile));
            services.AddDbContext <BookContext>(options => options.UseSqlite("Data Source=Book.db"));
            services.AddControllers()
            .AddNewtonsoftJson(options =>
                               options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            services.AddScoped <RatingConsumer>();
            services.AddScoped <AddAmountConsumer>();

            services.AddMassTransit(cfg =>
            {
                cfg.AddConsumer <RatingConsumer>();
                cfg.AddConsumer <AddAmountConsumer>();

                cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider, (cfg, host) =>
                {
                    cfg.ReceiveEndpoint(BusConstant.RateQueue, ep =>
                    {
                        ep.ConfigureConsumer <RatingConsumer>(provider);
                    });

                    cfg.ReceiveEndpoint(BusConstant.AddAmountQueue, ep =>
                    {
                        ep.ConfigureConsumer <AddAmountConsumer>(provider);
                    });
                }));
            });

            services.AddMassTransitHostedService();

            services.AddAuthentication("Bearer")
            .AddJwtBearer("Bearer", options =>
            {
                options.Authority            = "https://localhost:3117";
                options.RequireHttpsMetadata = false;
                options.Audience             = "book";
            });

            services.AddCors(options =>
            {
                options.AddPolicy("_myAllowSpecificOrigins",
                                  builder =>
                {
                    builder.WithOrigins(
                        "http://localhost:3000",
                        "http://localhost:3001"
                        )
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });
            services.AddScoped <BookService>();
            services.AddScoped <CategoryService>();
            services.AddScoped <ITokenConfiguration, TokenConfiguration>();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddMassTransit(cfg =>
            {
                cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider));
            });

            services.AddMassTransitHostedService();
        }
예제 #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMassTransit(cfg =>
            {
                cfg.AddConsumer <BookingValidateConsumer>();

                cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider, (cfg, host) =>
                {
                }));
            });
            services.AddMassTransitHostedService();


            services.AddControllers();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddMassTransit(cfg =>
            {
                cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider));
            });

            services.AddMassTransitHostedService();

            services.AddDbContext <OrderDbContext>
                (o => o.UseSqlServer(Configuration.
                                     GetConnectionString("OrderingDatabase")));

            services.AddSingleton <IOrderDataAccess, OrderDataAccess>();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddMassTransit(cfg =>
            {
                cfg.AddConsumer <OrderCardNumberValidateConsumer>();

                cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider, (cfg, host) =>
                {
                    cfg.ReceiveEndpoint(BusConstants.OrderQueue, ep =>
                    {
                        ep.ConfigureConsumer <OrderCardNumberValidateConsumer>(provider);
                    });
                }));
            });

            services.AddMassTransitHostedService();
        }
예제 #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.TryAddSingleton(KebabCaseEndpointNameFormatter.Instance);
            services.AddMassTransit(cfg =>
            {
                cfg.AddRequestClient <IStartBooking>();
                cfg.AddConsumer <StartBookingConsumer>();
                cfg.AddConsumer <BookingCancelledConsumer>();

                cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider));
            });

            services.AddMassTransitHostedService();
            services.AddDbContext <BookingDbContext>(a => a.UseSqlServer(Configuration.GetConnectionString("BookingDatabase")));

            services.AddSingleton <IBookingDataAccess, BookingDataAccess>();
        }
예제 #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers()
            .AddNewtonsoftJson(options =>
                               options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            services.AddMassTransit(cfg =>
            {
                cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider));
            });

            services.AddMassTransitHostedService();

            services.AddCors(options =>
            {
                options.AddPolicy("_myAllowSpecificOrigins",
                                  builder =>
                {
                    builder.WithOrigins(
                        "http://localhost:3000",
                        "http://localhost:3001"
                        )
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });

            services.AddAuthentication("Bearer")
            .AddJwtBearer("Bearer", options =>
            {
                options.Authority            = "https://localhost:3117";
                options.RequireHttpsMetadata = false;
                options.Audience             = "book";
            });

            services.AddDbContext <OrderContext>(options => options.UseSqlite("Data Source=Order.db"));
            services.AddScoped <ITokenConfiguration, TokenConfiguration>();
        }
예제 #10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddScoped <CommentConsumer>();

            services.AddMassTransit(cfg =>
            {
                cfg.AddConsumer <CommentConsumer>();

                cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider, (cfg, host) =>
                {
                    cfg.ReceiveEndpoint(BusConstant.CommentQueue, ep =>
                    {
                        ep.ConfigureConsumer <CommentConsumer>(provider);
                    });
                }));
            });

            services.AddMassTransitHostedService();

            services.AddDbContext <CommentContext>(options => options.UseSqlite("DataSource = Comment.db"));

            services.AddCors(options =>
            {
                options.AddPolicy("_myAllowSpecificOrigins",
                                  builder =>
                {
                    builder.WithOrigins(
                        "http://localhost:3000",
                        "http://localhost:3001"
                        )
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });
        }
예제 #11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <OrderContext>(options =>
                                                 options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddControllers();

            services.AddMassTransit(cfg =>
            {
                cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider));
                cfg.AddRequestClient <IOrderMessage>();
            });

            services.AddMassTransitHostedService();

            services.AddTransient <IDataAccess, DataAccess.DataAccess>();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Order_ms", Version = "v1"
                });
            });
        }
        static async Task Main(string[] args)
        {
            var saga = new OrderStateMachine();
            var repo = new InMemorySagaRepository <OrderStateData>();

            var builder = new HostBuilder()
                          .ConfigureServices((hostContext, services) =>
            {
                services.TryAddSingleton(KebabCaseEndpointNameFormatter.Instance);
                services.AddMassTransit(cfg =>
                {
                    cfg.AddBus(provider => RabbitMqBus.ConfigureBus(provider, (cfg, host) =>
                    {
                        cfg.ReceiveEndpoint(BusConstants.SagaBusQueue, e =>
                        {
                            e.StateMachineSaga(saga, repo);
                        });
                    }));
                });
                services.AddMassTransitHostedService();
            });

            await builder.RunConsoleAsync();
        }