SES-67 Add config to repositories
This commit is contained in:
parent
e3bcf28f46
commit
dfc3cdac98
@ -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<IRepository<Alignment>, AlignmentRepository>();
|
||||||
|
services.AddScoped<IRepository<Background>, BackgroundRepository>();
|
||||||
|
services.AddScoped<IRepository<Biography>, BiographyRepository>();
|
||||||
|
services.AddScoped<IRepository<Character>, CharacterRepository>();
|
||||||
|
services.AddScoped<IRepository<Class>, ClassRepository>();
|
||||||
|
services.AddScoped<IRepository<Race>, RaceRepository>();
|
||||||
|
services.AddScoped<IRepository<Statistics>, StatisticsRepository>();
|
||||||
|
services.AddScoped<IRepository<User>, UserRepository>();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,86 +1,89 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.HttpsPolicy;
|
using Microsoft.AspNetCore.HttpsPolicy;
|
||||||
using Microsoft.AspNetCore.SpaServices.AngularCli;
|
using Microsoft.AspNetCore.SpaServices.AngularCli;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using SessionCompanion.Configurations;
|
||||||
using SessionCompanion.Database;
|
using SessionCompanion.Database;
|
||||||
|
|
||||||
namespace SessionCompanion
|
namespace SessionCompanion
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
|
|
||||||
public Startup(IConfiguration configuration)
|
public Startup(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
Configuration = configuration;
|
Configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IConfiguration Configuration { get; }
|
public IConfiguration Configuration { get; }
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddControllersWithViews();
|
services.AddControllersWithViews();
|
||||||
services.AddDbContext<ApplicationDbContext>(options =>
|
services.AddDbContext<ApplicationDbContext>(options =>
|
||||||
options.UseSqlServer(
|
options.UseSqlServer(
|
||||||
Configuration.GetConnectionString("DefaultConnection")));
|
Configuration.GetConnectionString("DefaultConnection")));
|
||||||
// In production, the Angular files will be served from this directory
|
services.AddRepositories();
|
||||||
services.AddSpaStaticFiles(configuration =>
|
|
||||||
{
|
// In production, the Angular files will be served from this directory
|
||||||
configuration.RootPath = "ClientApp/dist";
|
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)
|
|
||||||
{
|
// 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<IServiceScopeFactory>().CreateScope())
|
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
|
||||||
{
|
{
|
||||||
serviceScope.ServiceProvider.GetService<ApplicationDbContext>().Database.Migrate();
|
serviceScope.ServiceProvider.GetService<ApplicationDbContext>().Database.Migrate();
|
||||||
}
|
}
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
app.UseExceptionHandler("/Error");
|
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.
|
// 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.UseHsts();
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
if (!env.IsDevelopment())
|
if (!env.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseSpaStaticFiles();
|
app.UseSpaStaticFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
endpoints.MapControllerRoute(
|
endpoints.MapControllerRoute(
|
||||||
name: "default",
|
name: "default",
|
||||||
pattern: "{controller}/{action=Index}/{id?}");
|
pattern: "{controller}/{action=Index}/{id?}");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.UseSpa(spa =>
|
app.UseSpa(spa =>
|
||||||
{
|
{
|
||||||
// To learn more about options for serving an Angular SPA from ASP.NET Core,
|
// To learn more about options for serving an Angular SPA from ASP.NET Core,
|
||||||
// see https://go.microsoft.com/fwlink/?linkid=864501
|
// see https://go.microsoft.com/fwlink/?linkid=864501
|
||||||
|
|
||||||
spa.Options.SourcePath = "ClientApp";
|
spa.Options.SourcePath = "ClientApp";
|
||||||
|
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
{
|
||||||
spa.UseAngularCliServer(npmScript: "start");
|
spa.UseAngularCliServer(npmScript: "start");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user