Unravel.AspNet.Identity.EntityFramework 0.1.20-alpha

This is a prerelease version of Unravel.AspNet.Identity.EntityFramework.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Unravel.AspNet.Identity.EntityFramework --version 0.1.20-alpha                
NuGet\Install-Package Unravel.AspNet.Identity.EntityFramework -Version 0.1.20-alpha                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Unravel.AspNet.Identity.EntityFramework" Version="0.1.20-alpha" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Unravel.AspNet.Identity.EntityFramework --version 0.1.20-alpha                
#r "nuget: Unravel.AspNet.Identity.EntityFramework, 0.1.20-alpha"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Unravel.AspNet.Identity.EntityFramework as a Cake Addin
#addin nuget:?package=Unravel.AspNet.Identity.EntityFramework&version=0.1.20-alpha&prerelease

// Install Unravel.AspNet.Identity.EntityFramework as a Cake Tool
#tool nuget:?package=Unravel.AspNet.Identity.EntityFramework&version=0.1.20-alpha&prerelease                

Unravel.AspNet.Identity.EntityFramework

Unravel provides AddIdentity() extension methods on IServiceCollection. The resulting IdentityBuilder provides methods and an extension point to configure Microsoft.AspNet.Identity services:

  • AddEntityFrameworkStores<TContext>() registers a context inheriting from IdentityDbContext<>, plus dependent store implementations
    • Calls SetPerOwinContext<T>(), from Unravel.AspNet.Identity, replacing CreatePerOwinContext<T>()

This is designed to directly migrate from the scaffolded Startup.Auth.cs pattern:

public void ConfigureAuth(IAppBuilder app)
{
    // Configure the db context, user manager and signin manager to use a single instance per request
    app.CreatePerOwinContext(ApplicationDbContext.Create);
    app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
    app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
    // ...
}

To:

public override void ConfigureServices(IServiceCollection services)
{
    services.AddIdentity<ApplicationUser>()
        .AddEntityFrameworkStores(ApplicationDbContext.Create)
        .AddUserManager<ApplicationUserManager>(ApplicationUserManager.Create)
        .AddSignInManager<ApplicationSignInManager>(ApplicationSignInManager.Create)
}

You can then refactor away from the Create methods to constructor injection, e.g.

--- a/App_Start/IdentityConfig.cs
+++ b/App_Start/IdentityConfig.cs
@@ -12,2 +12,3 @@
 using Microsoft.Owin.Security;
+using Microsoft.Owin.Security.DataProtection;
 using UnravelExamples.Identity.Models;
@@ -37,10 +38,10 @@
     {
-        public ApplicationUserManager(IUserStore<ApplicationUser> store)
+        public ApplicationUserManager(IUserStore<ApplicationUser> store, IDataProtectionProvider dataProtectionProvider)
             : base(store)
         {
+            Init(this, dataProtectionProvider);
         }

-        public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
+        private static ApplicationUserManager Init(ApplicationUserManager manager, IDataProtectionProvider dataProtectionProvider)
         {
-            var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));
             // Configure validation logic for usernames
@@ -80,3 +81,2 @@
             manager.SmsService = new SmsService();
-            var dataProtectionProvider = options.DataProtectionProvider;
             if (dataProtectionProvider != null)
--- a/App_Start/Startup.Auth.cs
+++ b/App_Start/Startup.Auth.cs
@@ -20,5 +20,5 @@
             services.AddIdentity<ApplicationUser>()
-                .AddEntityFrameworkStores(ApplicationDbContext.Create)
-                .AddUserManager<ApplicationUserManager>(ApplicationUserManager.Create)
-                .AddSignInManager<ApplicationSignInManager>(ApplicationSignInManager.Create)
+                .AddEntityFrameworkStores<ApplicationDbContext>()
+                .AddUserManager<ApplicationUserManager>()
+                .AddSignInManager<ApplicationSignInManager>()
                 ;
Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.36-alpha 177 5/26/2024
0.1.30-alpha 73 3/6/2024
0.1.26-alpha 53 3/4/2024
0.1.20-alpha 77 7/10/2023
0.1.13-alpha 90 7/10/2023
0.1.11-alpha 83 7/9/2023