Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using ProductService.DBContext;
- using ProductService.Repository;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using ProductService.Models;
- using ProductService.Queues;
- using ProductService.Events.Interfaces;
- using ProductService.Queues.Interfaces;
- using RabbitMQ.Client.Events;
- using RabbitMQ.Client;
- using ProductService.Queues.AMQP;
- using ProductService.Events;
- namespace ProductService
- {
- public class Startup
- {
- public Startup(IConfiguration configuration)
- {
- Configuration = configuration;
- }
- public IConfiguration Configuration { get; }
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
- services.Configure<QueueOptions>(Configuration.GetSection("QueueOptions"));
- services.Configure<AMQPOptions>(Configuration.GetSection("amqp"));
- services.AddDbContext<IProductContext,ProductContext>(o => o.UseSqlServer(Configuration.GetConnectionString("ProductDB")));
- services.AddTransient(typeof(IConnectionFactory), typeof(AMQPConnectionFactory));
- services.AddTransient(typeof(EventingBasicConsumer), typeof(AMQPEventingConsumer));
- services.AddTransient<IProductRepository, ProductRepository>();
- services.AddTransient<IProductContext, ProductContext>();
- services.AddSingleton(typeof(IReleasedProductsDataEventProcessor), typeof(ReleasedProductsDataEventProcessor));
- services.AddSingleton(typeof(ITakenProductsDataEventProcessor), typeof(TakenProductsDataEventProcessor));
- services.AddSingleton(typeof(IReleasedProductsDataEventSubscriber), typeof(AMQPReleasedProductsDataEventSubscriber));
- services.AddSingleton(typeof(ITakenProductsDataEventSubscriber), typeof(AMQPTakenProductsDataEventSubscriber));
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env, IReleasedProductsDataEventProcessor releasedProductsDataEventProcessor, ITakenProductsDataEventProcessor takenProductsDataEventProcessor)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- else
- {
- app.UseHsts();
- }
- app.UseHttpsRedirection();
- app.UseMvc();
- releasedProductsDataEventProcessor.Start();
- takenProductsDataEventProcessor.Start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement