解耦 Microsoft.AspNet.Identity.* [英] Decoupling Microsoft.AspNet.Identity.*

查看:15
本文介绍了解耦 Microsoft.AspNet.Identity.*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 2013 RC 中工作,正在使用新的 Microsoft.AspNet.Identity.* 包测试表单身份验证.

I am working in Visual Studio 2013 RC and am testing Forms Authentication using new Microsoft.AspNet.Identity.* packages.

我想整合这些概念(用户、角色等),但想使用我自己的不同程序集中的域模型 (POCO).我也不想创建对 Microsoft.AspNet.Identity.* dll 的依赖.

I would to integrate these concepts (Users, Roles, etc, etc) but want to use my own domain models (POCOs) which are in different assembly. I also don't want to create a dependency on Microsoft.AspNet.Identity.* dlls.

这可能吗?我找到了 这篇文章 说它不是,但这篇文章是基于预览而不是身份包的 RC 版本编写的.

Is that even possible? I found this article which says it is not, but the article is written based on Preview not RC versions of identity packages.

推荐答案

我已经更新了我的示例项目,你可以在这里找到:身份 RC1 示例

I have updated my sample project which you can find here: Identity RC1 sample

它现在实现了一个实体框架模型,它仍然需要对 Microsoft.AspNet.Identity.EntityFramework 的引用,因为我不想也重新实现所有 Store 类.但该示例展示了如何为模型使用自己的 POCO 类.

It now implements an entity framework model, it still require a reference to the Microsoft.AspNet.Identity.EntityFramework as I didn't want to reimplement all the Store classes also. But the sample shows how you can use your own POCO classes for the model.

如果您想从模型程序集中完全删除对 Microsoft.AspNet.Identity.EntityFramework 的依赖,您需要实现一个实现 IIdentityStore 接口的类,该接口具有以下接口的属性:

If you want to completely remove the dependency on Microsoft.AspNet.Identity.EntityFramework from your model assembly you need to implement an class implementing the IIdentityStore interface which has properties of the following interfaces:

  • IUserLoginStore
  • IRoleStore
  • IUserSecretStore
  • ITokenStore
  • IUserClaimStore
  • IUserManagementStore
  • IUserStore

IIdentityStore 类应位于与模型组件分开的组件中,并引用模型组件.IIdentityStore 程序集将依赖于 ASP.Net Identity 核心.

The IIdentityStore class should be in an assembly separate from your model assembly, with a reference to your model assembly. The IIdentityStore assembly would be dependent on ASP.Net Identity core.

您对 IIdentityStore 的自定义实现需要能够在您的 POCO 类和 ASP.Net Identity 接口(例如 IUser、IUserSecret 等)之间进行转换.

Your custom implementation of IIdentityStore would need to somwhow be able to convert to and from your POCO classes to ASP.Net Identity interfaces such as IUser, IUserSecret etc.

在我看来,如果您无论如何都在为您的商店使用 EF,那么工作量很大,但收益甚微.

Seems to me to be a lot of work for little gain, if you are using EF for your stores anyway.

依赖 AspNet.Identity.Core 程序集并让您的一些 POCO 类实现一个小接口,对我来说似乎要简单得多.

Taking a dependency on the AspNet.Identity.Core assembly and have some of your POCO classes implementing one tiny interface each, seems a lot simpler to me.

这篇关于解耦 Microsoft.AspNet.Identity.*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆