41 lines
1.5 KiB
C#
41 lines
1.5 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System;
|
|
using Microsoft.AspNet.Identity.EntityFramework;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Microsoft.AspNet.Identity
|
|
{
|
|
/// <summary>
|
|
/// Default services
|
|
/// </summary>
|
|
public class IdentityEntityFrameworkServices
|
|
{
|
|
public static IServiceCollection GetDefaultServices(Type userType, Type roleType, Type contextType, Type keyType = null)
|
|
{
|
|
Type userStoreType;
|
|
Type roleStoreType;
|
|
if (keyType != null)
|
|
{
|
|
userStoreType = typeof(UserStore<,,,>).MakeGenericType(userType, roleType, contextType, keyType);
|
|
roleStoreType = typeof(RoleStore<,,>).MakeGenericType(roleType, contextType, keyType);
|
|
}
|
|
else
|
|
{
|
|
userStoreType = typeof(UserStore<,,>).MakeGenericType(userType, roleType, contextType);
|
|
roleStoreType = typeof(RoleStore<,>).MakeGenericType(roleType, contextType);
|
|
}
|
|
|
|
var services = new ServiceCollection();
|
|
services.AddScoped(
|
|
typeof(IUserStore<>).MakeGenericType(userType),
|
|
userStoreType);
|
|
services.AddScoped(
|
|
typeof(IRoleStore<>).MakeGenericType(roleType),
|
|
roleStoreType);
|
|
return services;
|
|
}
|
|
}
|
|
} |