From dfc3cdac982c6f09edd19b5e7d98212196cef7ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20G=C3=B3rzy=C5=84ski?= Date: Thu, 3 Dec 2020 18:52:53 +0100 Subject: [PATCH] SES-67 Add config to repositories --- .../Configurations/RepositoryConfiguration.cs | 28 +++ SessionCompanion/SessionCompanion/Startup.cs | 163 +++++++++--------- 2 files changed, 111 insertions(+), 80 deletions(-) create mode 100644 SessionCompanion/SessionCompanion/Configurations/RepositoryConfiguration.cs diff --git a/SessionCompanion/SessionCompanion/Configurations/RepositoryConfiguration.cs b/SessionCompanion/SessionCompanion/Configurations/RepositoryConfiguration.cs new file mode 100644 index 0000000..8db8860 --- /dev/null +++ b/SessionCompanion/SessionCompanion/Configurations/RepositoryConfiguration.cs @@ -0,0 +1,28 @@ +using Microsoft.Extensions.DependencyInjection; +using SessionCompanion.Database.Repositories; +using SessionCompanion.Database.Repositories.Base; +using SessionCompanion.Database.Tables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SessionCompanion.Configurations +{ + public static class RepositoryConfiguration + { + public static IServiceCollection AddRepositories(this IServiceCollection services) + { + services.AddScoped, AlignmentRepository>(); + services.AddScoped, BackgroundRepository>(); + services.AddScoped, BiographyRepository>(); + services.AddScoped, CharacterRepository>(); + services.AddScoped, ClassRepository>(); + services.AddScoped, RaceRepository>(); + services.AddScoped, StatisticsRepository>(); + services.AddScoped, UserRepository>(); + + return services; + } + } +} diff --git a/SessionCompanion/SessionCompanion/Startup.cs b/SessionCompanion/SessionCompanion/Startup.cs index 74d6b69..ac583c8 100644 --- a/SessionCompanion/SessionCompanion/Startup.cs +++ b/SessionCompanion/SessionCompanion/Startup.cs @@ -1,86 +1,89 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; -using Microsoft.AspNetCore.SpaServices.AngularCli; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.SpaServices.AngularCli; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using SessionCompanion.Configurations; using SessionCompanion.Database; -namespace SessionCompanion -{ - 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.AddControllersWithViews(); - services.AddDbContext(options => - options.UseSqlServer( - Configuration.GetConnectionString("DefaultConnection"))); - // In production, the Angular files will be served from this directory - services.AddSpaStaticFiles(configuration => - { - configuration.RootPath = "ClientApp/dist"; - }); - - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { +namespace SessionCompanion +{ + 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.AddControllersWithViews(); + services.AddDbContext(options => + options.UseSqlServer( + Configuration.GetConnectionString("DefaultConnection"))); + services.AddRepositories(); + + // In production, the Angular files will be served from this directory + services.AddSpaStaticFiles(configuration => + { + configuration.RootPath = "ClientApp/dist"; + }); + + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { using (var serviceScope = app.ApplicationServices.GetRequiredService().CreateScope()) { serviceScope.ServiceProvider.GetService().Database.Migrate(); - } - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - else - { - app.UseExceptionHandler("/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(); - if (!env.IsDevelopment()) - { - app.UseSpaStaticFiles(); - } - - app.UseRouting(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllerRoute( - name: "default", - pattern: "{controller}/{action=Index}/{id?}"); - }); - - app.UseSpa(spa => - { - // To learn more about options for serving an Angular SPA from ASP.NET Core, - // see https://go.microsoft.com/fwlink/?linkid=864501 - - spa.Options.SourcePath = "ClientApp"; - - if (env.IsDevelopment()) - { - spa.UseAngularCliServer(npmScript: "start"); - } - }); - } - } -} + } + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + app.UseExceptionHandler("/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(); + if (!env.IsDevelopment()) + { + app.UseSpaStaticFiles(); + } + + app.UseRouting(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllerRoute( + name: "default", + pattern: "{controller}/{action=Index}/{id?}"); + }); + + app.UseSpa(spa => + { + // To learn more about options for serving an Angular SPA from ASP.NET Core, + // see https://go.microsoft.com/fwlink/?linkid=864501 + + spa.Options.SourcePath = "ClientApp"; + + if (env.IsDevelopment()) + { + spa.UseAngularCliServer(npmScript: "start"); + } + }); + } + } +}