Add AddIdentityEntityFramework

This commit is contained in:
Hao Kung 2014-05-15 18:46:56 -07:00
Родитель da44b71c09
Коммит 7bf68e0e58
4 изменённых файлов: 13 добавлений и 23 удалений

Просмотреть файл

@ -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>>();