78 lines
2.6 KiB
C#
78 lines
2.6 KiB
C#
using Fluxor;
|
|
using KoogleApp.Data;
|
|
using KoogleApp.Data.Repository;
|
|
using KoogleApp.Hub;
|
|
using System.Reflection;
|
|
using Fluxor.Blazor.Web.ReduxDevTools;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace KoogleApp.Services
|
|
{
|
|
public static class ServiceExtension
|
|
{
|
|
public static IServiceCollection AddDbServices(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
var connectionString = configuration.GetConnectionString("AppDb") ?? throw new InvalidOperationException("Connection string 'AppDb' not found.");
|
|
|
|
//services.AddDbContext<AppDbContext>(options =>
|
|
// options.UseSqlServer(connectionString));
|
|
|
|
services.AddDatabaseDeveloperPageExceptionFilter();
|
|
|
|
services.AddIdentityCore<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
|
|
.AddEntityFrameworkStores<AppDbContext>()
|
|
.AddSignInManager()
|
|
.AddDefaultTokenProviders();
|
|
|
|
services.AddDbContextFactory<AppDbContext>(options =>
|
|
options.UseSqlServer(connectionString)
|
|
);
|
|
|
|
|
|
return services;
|
|
}
|
|
|
|
public static IServiceCollection AddAppServices(this IServiceCollection services)
|
|
{
|
|
services.AddFluxor(x =>
|
|
x.ScanAssemblies(typeof(ServiceExtension).Assembly)
|
|
.UseReduxDevTools());
|
|
|
|
services.AddScopedEventAggregator();
|
|
services.AddScoped<SessionStorage>();
|
|
|
|
// Memory Cache
|
|
services.AddMemoryCache();
|
|
|
|
var uesInMemory = true; // builder.Environment.IsDevelopment()
|
|
|
|
|
|
// ENTWICKLUNG: In-Memory Repository
|
|
if (uesInMemory)
|
|
{
|
|
services.AddSingleton<IPlayerRepository, PlayerRepository>();
|
|
services.AddSingleton<IPlayerExpenseRepository, PlayerExpenseRepository>();
|
|
}
|
|
// PRODUKTION: Entity Framework Repository
|
|
else
|
|
{
|
|
services.AddScoped<IPlayerRepository, PlayerRepository>();
|
|
services.AddScoped<IPlayerExpenseRepository, PlayerExpenseRepository>();
|
|
}
|
|
services.AddSingleton<IDayRepository, DayRepository>();
|
|
|
|
services.AddSingleton<IGameStatusDataService, GameStatusDataService>();
|
|
|
|
|
|
// Shared Data Service (Scoped = pro User-Session)
|
|
services.AddScoped<SharedDataService>();
|
|
services.AddScoped<HubConnectionService>();
|
|
|
|
services.AddSingleton<GameTypeService>();
|
|
|
|
return services;
|
|
}
|
|
}
|
|
}
|