50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
using Koogle.Domain.Interfaces;
|
|
using Koogle.Infrastrcuture.Services;
|
|
using KoogleApp.Data;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Koogle.Infrastructure
|
|
{
|
|
public static class DependencyInjection
|
|
{
|
|
public static IServiceCollection AddInfrastructure(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)
|
|
);
|
|
|
|
|
|
// HTTP Context Accessor (für CurrentUserService)
|
|
services.AddHttpContextAccessor();
|
|
|
|
// Current UserProfile Service
|
|
services.AddScoped<ICurrentUserService, CurrentUserService>();
|
|
|
|
return services;
|
|
}
|
|
}
|
|
}
|