Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.95 KB | None | 0 0
  1. using ProductService.DBContext;
  2. using ProductService.Repository;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.EntityFrameworkCore;
  7. using Microsoft.Extensions.Configuration;
  8. using Microsoft.Extensions.DependencyInjection;
  9. using ProductService.Models;
  10. using ProductService.Queues;
  11. using ProductService.Events.Interfaces;
  12. using ProductService.Queues.Interfaces;
  13. using RabbitMQ.Client.Events;
  14. using RabbitMQ.Client;
  15. using ProductService.Queues.AMQP;
  16. using ProductService.Events;
  17.  
  18. namespace ProductService
  19. {
  20.     public class Startup
  21.     {
  22.         public Startup(IConfiguration configuration)
  23.         {
  24.             Configuration = configuration;
  25.         }
  26.  
  27.         public IConfiguration Configuration { get; }
  28.  
  29.         // This method gets called by the runtime. Use this method to add services to the container.
  30.         public void ConfigureServices(IServiceCollection services)
  31.         {
  32.             services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  33.            
  34.  
  35.             services.Configure<QueueOptions>(Configuration.GetSection("QueueOptions"));
  36.             services.Configure<AMQPOptions>(Configuration.GetSection("amqp"));
  37.             services.AddDbContext<IProductContext,ProductContext>(o => o.UseSqlServer(Configuration.GetConnectionString("ProductDB")));
  38.  
  39.             services.AddTransient(typeof(IConnectionFactory), typeof(AMQPConnectionFactory));
  40.             services.AddTransient(typeof(EventingBasicConsumer), typeof(AMQPEventingConsumer));
  41.  
  42.             services.AddTransient<IProductRepository, ProductRepository>();
  43.             services.AddTransient<IProductContext, ProductContext>();
  44.             services.AddSingleton(typeof(IReleasedProductsDataEventProcessor), typeof(ReleasedProductsDataEventProcessor));
  45.             services.AddSingleton(typeof(ITakenProductsDataEventProcessor), typeof(TakenProductsDataEventProcessor));
  46.             services.AddSingleton(typeof(IReleasedProductsDataEventSubscriber), typeof(AMQPReleasedProductsDataEventSubscriber));
  47.             services.AddSingleton(typeof(ITakenProductsDataEventSubscriber), typeof(AMQPTakenProductsDataEventSubscriber));
  48.            
  49.            
  50.         }
  51.  
  52.         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  53.         public void Configure(IApplicationBuilder app, IHostingEnvironment env, IReleasedProductsDataEventProcessor releasedProductsDataEventProcessor, ITakenProductsDataEventProcessor takenProductsDataEventProcessor)
  54.         {
  55.             if (env.IsDevelopment())
  56.             {
  57.                 app.UseDeveloperExceptionPage();
  58.             }
  59.             else
  60.             {
  61.                 app.UseHsts();
  62.             }
  63.  
  64.             app.UseHttpsRedirection();
  65.             app.UseMvc();
  66.  
  67.             releasedProductsDataEventProcessor.Start();
  68.             takenProductsDataEventProcessor.Start();
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement