// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, KweetContext kweetContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } kweetContext.Database.Migrate(); // var services = app.ApplicationServices.CreateScope().ServiceProvider; // // var lifeTime = services.GetService<IHostApplicationLifetime>(); // var bus = services.GetService<IBus>(); // lifeTime.ApplicationStarted.Register(() => // { // var subscriber = new AutoSubscriber(bus, "Kweet"); // subscriber.Subscribe(Assembly.GetExecutingAssembly().GetTypes()); // // subscriber.SubscribeAsync(Assembly.GetExecutingAssembly().GetTypes()); // }); // lifeTime.ApplicationStopped.Register(() => bus.Dispose()); app.ApplicationServices.GetRequiredService <AutoSubscriber>().SubscribeAsync(Assembly.GetExecutingAssembly().GetTypes()); app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); app.UseAuthentication(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "KweetService.API v1")); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
protected void Init() { var dbContext = new DbContextOptionsBuilder <KweetContext>().UseInMemoryDatabase("Test"); Context = new KweetContext(dbContext.Options); Context.Database.EnsureCreated(); SetProfiles(); }