我想问 Owin 是否存在用户。把我在网上找到的随机东西放在一起,我最终得到了这个(完全未经测试的代码):
/// <summary> Returns true if the TestUser user exists in the membership database. </summary>
public static bool UserExists(ApplicationDbContext db, string username)
{
var userManager = new Microsoft.AspNet.Identity.UserManager<ApplicationUser>(
new Microsoft.AspNet.Identity.EntityFramework.UserStore<ApplicationUser>(db));
var user = userManager.FindByName(username);
return (user != null);
}
我的问题是,我真的需要那个又长又丑的表达式来获得一个新的 UserManager 吗?还是有更好、更有效、更清洁或更正确的方法来做到这一点?
现在我仔细观察一下,我发现 UserManager 和 UserStore 都是一次性的。我想把东西包装成using
块吗?