41 lines
1.6 KiB
C#
41 lines
1.6 KiB
C#
// Copyright (c) Microsoft Open Technologies, Inc. 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.Framework.ConfigurationModel;
|
|
using Microsoft.Framework.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, IConfiguration config = 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;
|
|
}
|
|
}
|
|
} |