mirror of
https://github.com/TomasiDeveloping/PlayerManagement.git
synced 2026-04-16 09:12:20 +00:00
43 lines
1.4 KiB
C#
43 lines
1.4 KiB
C#
using System.Reflection;
|
|
using Database.Entities;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Database;
|
|
|
|
public static class DatabaseDependencyInjection
|
|
{
|
|
public static IServiceCollection AddDatabase(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.AddDataProtection();
|
|
|
|
services.AddDbContext<ApplicationContext>(options =>
|
|
{
|
|
options.UseSqlServer(configuration.GetConnectionString("ApplicationDbConnection"));
|
|
});
|
|
|
|
services.AddIdentityCore<User>(options =>
|
|
{
|
|
options.Password.RequiredLength = 7;
|
|
options.Password.RequireDigit = true;
|
|
options.Password.RequireLowercase = true;
|
|
options.Password.RequireUppercase = true;
|
|
options.Password.RequireNonAlphanumeric = true;
|
|
|
|
options.User.RequireUniqueEmail = true;
|
|
})
|
|
.AddRoles<IdentityRole<Guid>>()
|
|
.AddTokenProvider<DataProtectorTokenProvider<User>>("PlayerManagerApi")
|
|
.AddEntityFrameworkStores<ApplicationContext>()
|
|
.AddDefaultTokenProviders();
|
|
|
|
services.Configure<DataProtectionTokenProviderOptions>(options =>
|
|
{
|
|
options.TokenLifespan = TimeSpan.FromHours(2);
|
|
});
|
|
|
|
return services;
|
|
}
|
|
} |