// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime, IOptions <ServiceDiscoveryOptions> serviceOptions, IConsulClient consul) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // 启动的时候注册服务 applicationLifetime.ApplicationStarted.Register(() => { RegisterServic(app, serviceOptions, consul); }); applicationLifetime.ApplicationStopped.Register(() => { DeRegisterServic(app, serviceOptions, consul); }); app.UseCap(); app.UseAuthentication(); app.UseMvc(); UserContextSeed.SeedAsync(app, loggerFactory).Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IHostApplicationLifetime applicationLifetime, IOptions <ServiceDiscoveryOptions> serviceOptions, IConsulClient consul) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); //app.UseAuthorization(); app.UseAuthentication(); applicationLifetime.ApplicationStarted.Register(() => { RegisterService(app, applicationLifetime, loggerFactory, serviceOptions, consul); }); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); UserContextSeed.SeedAsync(app, loggerFactory).Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime, IOptions <ServiceDisvoveryOptions> serviceOptions, IConsulClient consul) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseAuthentication(); //app.UseCap(); //启动时候 注册服务 applicationLifetime.ApplicationStarted.Register(() => ResiterService(app, serviceOptions, consul, applicationLifetime)); //todo 停止时 移除服务 applicationLifetime.ApplicationStopped.Register(() => DeRegisterService(app, serviceOptions, consul)); //app.UseHttpsRedirection(); app.UseMvc(); UserContextSeed.SeedAsync(app, loggerFactory).Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime lifetime, IOptions <ServiceDisvoveryOptions> serviceOptions, IConsulClient consul) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //启动时注册服务 lifetime.ApplicationStarted.Register(() => { RegisterService(app, serviceOptions, consul); }); //停止时移除服务 lifetime.ApplicationStarted.Register(() => { DeRegisterService(app, serviceOptions, consul); }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "api/{controller}/{action}" ); }); UserContextSeed.SeedAsync(app, loggerFactory).Wait(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var loggerFactory = services.GetRequiredService <ILoggerFactory>(); try { var context = services.GetRequiredService <StoreContext>(); await context.Database.MigrateAsync(); await StoreContextSeed.SeedAsync(context, loggerFactory); var userManager = services.GetRequiredService <UserManager <AppUser> >(); var userContext = services.GetRequiredService <UserContext>(); await userContext.Database.MigrateAsync(); await UserContextSeed.SeedUsersAsync(userManager); } catch (Exception exception) { var logger = loggerFactory.CreateLogger <Program>(); logger.LogError(exception, "An error occured during migration!"); } } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime lifetime, IOptions <ServiceDiscoveryOptions> serviceOptions, IConsulClient consul) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //注册consul //详见:http://michaco.net/blog/ServiceDiscoveryAndHealthChecksInAspNetCoreWithConsul?tag=Consul lifetime.ApplicationStarted.Register(() => { RegisterService(app, serviceOptions, consul); }); lifetime.ApplicationStopped.Register(() => { DeregisterService(app, serviceOptions, consul); }); //app.UseCap(); app.UseAuthentication(); app.UseMvc(); RegisterZipkinService(app, loggerFactory, lifetime); UserContextSeed.SeedAsync(app, loggerFactory).Wait(); }
public UserContext(IUserDatabaseSettings settings) { var client = new MongoClient(settings.ConnectionString); var database = client.GetDatabase(settings.DatabaseName); Users = database.GetCollection <User>(settings.CollectionName); UserContextSeed.SeedData(Users); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); UserContextSeed.SeedAsync(app, loggerFactory).Wait(); }
static void Main() { //Use this for dummy data UserContextSeed.Seed(); TopicSeed.Seed(); SectionSeed.Seed(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new ConferenceDetails()); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); ////有bug 有逻辑错误 //InitUserDatabase(app);//可以传递app UserContextSeed.SeedAsync(app, loggerFactory).Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(); UserContextSeed.SeedAsync(app, loggerFactory, 0).Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } //InitUserDatabase(app); UserContextSeed.SeedAsync(app).Wait(); //app.UseHttpsRedirection(); app.UseMvc(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); try { // mysql的创建 会比web的创建慢 // 这里防止创建数据库失败,只要抛异常自动重启 using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <UserContext>(); UserContextSeed.Initialize(context); } host.Run(); } catch (Exception) { throw; } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime, IOptions <ServiceDiscoveryOptions> serviceOptions, IConsulClient consul) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //进行服务注册 //程序启动的时候注册Consul服务 applicationLifetime.ApplicationStarted.Register(() => { RegisterService(app, serviceOptions, consul); }); //程序停止的时候移除服务 applicationLifetime.ApplicationStopped.Register(() => { DeRegisterService(app, serviceOptions, consul); }); app.UseMvc(); UserContextSeed.SeedAsync(app, loggerFactory).Wait(); //启用中间件服务生成Swagger作为JSON终结点 app.UseSwagger(); //启用中间件服务对swagger-ui,指定Swagger JSON终结点 app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); //注意,在使用初始化种子数据的时候,首先要保证数据库存在,所以可以先注释掉它 //InitUserDatabase(app); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime, IOptions <ServiceDiscoveryOptions> serviceOptions, IConsulClient consul) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } #region --服务发现注册-- //启动的时候注册服务 applicationLifetime.ApplicationStarted.Register(() => { RegisterService(app, serviceOptions, consul); }); //停止的时候移除服务 applicationLifetime.ApplicationStopped.Register(() => { DeRegisterService(app, serviceOptions, consul); }); #endregion --服务发现注册-- RegisterZipKinTrace(app, loggerFactory, applicationLifetime); // app.UseCap();//2.3版本之后不再需要注册 //身份认证管道配置 app.UseAuthentication(); app.UseMvc(); //执行数据库迁移 UserContextSeed.SeedAsync(app, loggerFactory).Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime application, IOptions <ServiceDisvoveryOptions> serviceOptions, IConsulClient consul) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } if (serviceOptions.Value.Enable)// 是否启用Consul { // 启动时注册服务 application.ApplicationStarted.Register(() => { RegisterService(app, serviceOptions, consul); }); // 停止的时候移除服务 application.ApplicationStopped.Register(() => { DeRegisterService(app, serviceOptions, consul); }); } app.UseAuthentication(); app.UseMvc(); UserContextSeed.SeedAsync(app, loggerFactory).Wait(); }