зеркало из https://github.com/aspnet/Identity.git
Add AddIdentityEntityFramework
This commit is contained in:
Родитель
da44b71c09
Коммит
7bf68e0e58
|
@ -14,9 +14,7 @@ namespace Microsoft.AspNet.Identity
|
|||
where TRole : EntityRole
|
||||
{
|
||||
builder.Services.AddScoped<IUserStore<TUser>, InMemoryUserStore<TUser>>();
|
||||
builder.Services.AddScoped<UserManager<TUser>, UserManager<TUser>>();
|
||||
builder.Services.AddScoped<IRoleStore<TRole>, EntityRoleStore<TRole>>();
|
||||
builder.Services.AddScoped<RoleManager<TRole>, RoleManager<TRole>>();
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
@ -27,6 +25,7 @@ namespace Microsoft.AspNet.Identity
|
|||
builder.Services.AddScoped<UserManager<TUser>>();
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static IdentityBuilder<TUser, IdentityRole> AddEntity<TUser, TContext>(this IdentityBuilder<TUser, IdentityRole> builder)
|
||||
where TUser : User where TContext : DbContext
|
||||
{
|
||||
|
@ -35,5 +34,6 @@ namespace Microsoft.AspNet.Identity
|
|||
builder.Services.AddScoped<TContext>();
|
||||
return builder;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -9,20 +9,13 @@ namespace Microsoft.Framework.DependencyInjection
|
|||
{
|
||||
public static class IdentityEntityServiceCollectionExtensions
|
||||
{
|
||||
//public static IdentityBuilder<TUser, IdentityRole> AddEntity<TUser>(this ServiceCollection services)
|
||||
// where TUser : User
|
||||
//{
|
||||
// services.AddScoped<IUserStore<TUser>, UserStore<TUser>>();
|
||||
// services.AddScoped<UserManager<TUser>>();
|
||||
// return services;
|
||||
//}
|
||||
|
||||
//public static ServiceCollection AddEntity<TUser, TContext>(this ServiceCollection services)
|
||||
// where TUser : User where TContext : DbContext
|
||||
//{
|
||||
// services.AddEntity<TUser>();
|
||||
// services.AddScoped<DbContext, TContext>();
|
||||
// return services;
|
||||
//}
|
||||
public static IdentityBuilder<TUser, IdentityRole> AddIdentityEntityFramework<TContext, TUser>(this ServiceCollection services)
|
||||
where TUser : User where TContext : DbContext
|
||||
{
|
||||
var builder = services.AddIdentity<TUser, IdentityRole>();
|
||||
services.AddScoped<TContext>();
|
||||
services.AddScoped<IUserStore<TUser>, UserStore<TUser, TContext>>();
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,6 +14,8 @@ namespace Microsoft.Framework.DependencyInjection
|
|||
{
|
||||
services.Add(IdentityServices.GetDefaultUserServices<TUser>());
|
||||
services.Add(IdentityServices.GetDefaultRoleServices<TRole>());
|
||||
services.AddScoped<UserManager<TUser>>();
|
||||
services.AddScoped<RoleManager<TRole>>();
|
||||
services.AddTransient<IOptionsSetup<IdentityOptions>, IdentityOptionsSetup>();
|
||||
services.AddSingleton<IOptionsAccessor<IdentityOptions>, OptionsAccessor<IdentityOptions>>();
|
||||
return new IdentityBuilder<TUser, TRole>(services);
|
||||
|
|
|
@ -3,17 +3,12 @@
|
|||
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Identity.Test;
|
||||
using Microsoft.AspNet.Testing;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Data.Entity.Metadata;
|
||||
using Microsoft.Data.Entity.InMemory;
|
||||
using Microsoft.Data.Entity.SqlServer;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.DependencyInjection.Fallback;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
|
@ -37,7 +32,7 @@ namespace Microsoft.AspNet.Identity.Entity.Test
|
|||
builder.UseServices(services =>
|
||||
{
|
||||
services.AddEntityFramework().AddSqlServer();
|
||||
services.AddIdentity<ApplicationUser>().AddEntity<ApplicationUser, ApplicationDbContext>();
|
||||
services.AddIdentityEntityFramework<ApplicationDbContext, ApplicationUser>();
|
||||
});
|
||||
|
||||
var userStore = builder.ApplicationServices.GetService<IUserStore<ApplicationUser>>();
|
||||
|
|
Загрузка…
Ссылка в новой задаче