我正在尝试实现 UserStore,但我也想实现 UserEmailStore 和 UserLockoutStore 等。我注意到所有 User*Store 都基于 UserStore,没问题。但我查看了 UserManager,发现对我来说很奇怪。您可以向 UserManager 注入多种类型的存储,但始终只能注入一种。但是 UserManager 可以根据您注入的类型与所有这些一起使用。
来自 UserManager 的 Fox 示例方法 GetLockoutEndDateAsync
public virtual async Task<DateTimeOffset?> GetLockoutEndDateAsync(TUser user)
{
this.ThrowIfDisposed();
IUserLockoutStore<TUser> userLockoutStore = this.GetUserLockoutStore();
if ((object) user == null)
throw new ArgumentNullException("user");
TUser user1 = user;
CancellationToken cancellationToken = this.CancellationToken;
return await userLockoutStore.GetLockoutEndDateAsync(user1, cancellationToken);
}
方法this.GetUserLockoutStore看起来像这样
internal IUserLockoutStore<TUser> GetUserLockoutStore()
{
IUserLockoutStore<TUser> userLockoutStore = this.Store as IUserLockoutStore<TUser>;
if (userLockoutStore != null)
return userLockoutStore;
throw new NotSupportedException(Resources.StoreNotIUserLockoutStore);
}
还有其他方法,例如
- 获取电子邮件商店
- 获取电话号码存储
- GetClaimStore
- 获取登录商店
- ...
所以这意味着商店必须基于您要使用的正确界面。
我的问题是,如何处理这个问题?我应该基于所有可能的 User*Store 接口实现一个商店吗?或者你能建议另一种解决方案吗?
提前致谢