11

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

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.

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.

zam6ak
  • 7,229
  • 11
  • 46
  • 84

3 Answers3

5

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

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.

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

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.

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.

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

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.

Olav Nybø
  • 11,454
  • 8
  • 42
  • 34
  • Hmm even those are part of `Microsoft.AspNet.Identity` core package - are they not? – zam6ak Sep 11 '13 at 22:36
  • You are right, I have updated my answer. My POCOs in my sample project also implement IUser, IUserSecret interfaces which are also in the Microsoft.AspNet.Identity.Core assembly. – Olav Nybø Sep 12 '13 at 05:47
  • 2
    Taking on this dependency (to implement interface) definatelly simplifies things, but I don't think it will work for us. If you have domain DLL that has your models, and a console app that uses it as well, then it makes no sense to carry ASP.NET dependency. Besides, once you start down that road (picking up dependencies on core domain model)...after few years, you end up with a nightmare :) – zam6ak Sep 12 '13 at 14:19
1

Yes this is a fully supported scenario, basically you will want to use exclude using the Microsoft.AspNet.Identity.EntityFramework dll which has the default EF implementation, but you should be able to reuse the Manager classes and just implement your own custom Stores using your own POCOs which the manager will use just fine via the interface. For RTM its been streamlined and simplified a bit more, I believe the RC version was not quite as streamlined yet.

Updated You can get early access to the RTM bits here: MyGet

Community
  • 1
  • 1
Hao Kung
  • 28,040
  • 6
  • 84
  • 93
  • Will there be an example on how to accomplish this (with custom Store) for RTM? I would love to be able to leverage OWIN security and just be able to "tell" it where to find users, profiles, roles, etc, etc using my own domain POCOs... – zam6ak Sep 11 '13 at 20:50
  • Yes there will be several examples with RTM that will demonstrate this, Azure Table Storage stores, a MySql store, stores using existing databases (which would probably the most similar to what your scenario) – Hao Kung Sep 11 '13 at 21:38
  • I looking forward to these examples (especially existing db/model) and hope situation will be different than the one described in @Olav Nybø answer and comments... – zam6ak Sep 12 '13 at 14:21
  • Adding a link where you can preview the RTM bits to my answer – Hao Kung Sep 13 '13 at 19:25
  • 1
    @HaoKung do you have a link the examples you mentioned that allow implementing different stores with Asp.NET Identity? – David Sulpy Nov 18 '13 at 19:53
1

Just in case. Maybe I can help someone. exorcising entity framework from asp.net.Identity

I'd created separate project(class library), then add ref to asp.identity.core, then I'd implemented my UserStore class there, and feed it my Identity config in Web project.

It works fine in project with complex n-tier architecture.

Pavel
  • 21
  • 2
  • Thank you! Another helpful article is [Persistence-Ignorant ASP.NET Identity with Patterns](http://timschreiber.com/2015/01/14/persistence-ignorant-asp-net-identity-with-patterns-part-1/) – nrodic Jun 16 '16 at 08:28