public static void Main(string[] args) { //CreateHostBuilder(args).Build().Run(); var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var serviceProvider = scope.ServiceProvider; try { DataScheduler.Start(serviceProvider); } catch (Exception) { throw; } } host.Run(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var serviceProvider = scope.ServiceProvider; try { DataScheduler.Start(serviceProvider); } catch (Exception) { } var defaultApp = FirebaseApp.Create(new AppOptions() { Credential = GoogleCredential.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "key.json")), }); host.Run(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // 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.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); var scopeFactory = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>(); var scope = scopeFactory.CreateScope(); // Добавление админа и библиотекаря, если их нет. var userManager = scope.ServiceProvider.GetRequiredService <UserManager <User> >(); var rolesManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeAsync(userManager, rolesManager); // Фоновая задача. DataScheduler.Start(scope.ServiceProvider); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using var scope = host.Services.CreateScope();; var services = scope.ServiceProvider; try { DataScheduler.Start(services); var userManager = services.GetRequiredService <UserManager <Employee> >(); var roleManager = services.GetRequiredService <RoleManager <Role> >(); await RoleInitializer.Initialize(roleManager, userManager); } catch (Exception e) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(e, "�������� ���������� ��� ������������� �����"); } host.Run(); }