Files
mixtape/zero/Identity/IdentityBuilderExtensions.cs
T
2022-12-12 00:15:21 +01:00

21 lines
833 B
C#

using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace zero.Identity;
public static class IdentityBuilderExtensions
{
/// <summary>
/// Adds an implementation of identity information stores.
/// </summary>
public static IdentityBuilder AddZeroIdentityStores(this IdentityBuilder builder)
{
Type userStoreType = typeof(ZeroUserStore<,>).MakeGenericType(builder.UserType, builder.RoleType);
Type roleStoreType = typeof(ZeroRoleStore<>).MakeGenericType(builder.RoleType);
builder.Services.TryAddScoped(typeof(IUserStore<>).MakeGenericType(builder.UserType), userStoreType);
builder.Services.TryAddScoped(typeof(IRoleStore<>).MakeGenericType(builder.RoleType), roleStoreType);
return builder;
}
}