Decoupling Identity from Data layer in Onion Architecture in Dotnet Core

135 Views Asked by At

I have an IdentityDbContext in my data layer but I can't use and packages form Microsoft.AspNetCore. I need to decouple it form the data layer so I can reuse the database context without Identity in a different domain service.

IdentityDbContext is inside Microsoft.AspNetCore

using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace DataLayer.Data
{
    public class MyDbContext : IdentityDbContext<ApplicationUser>
    {
        public DbSet<Table1> Table1 { get; set; }
        public DbSet<Table2> Table2 { get; set; }
        public MyDbContext(DbContextOptions<MyDbContext> options) 
        : base(options) { } 
    }
}

I want to achieve something like this where I have Dbcontext in my data layer and later in my web layer I can configure Identity

using Microsoft.EntityFrameworkCore;

namespace DataLayer.Data
{
    public class MyDbContext : DbContext
    {
        public DbSet<Table1> Table1 { get; set; }
        public DbSet<Table2> Table2 { get; set; }
        public MyDbContext(DbContextOptions<MyDbContext> options) 
        : base(options) { }
    }
}

I had a look at this post but it is about asp.net

Decoupling ASP.NET MVC 5 Identity to allow implementing a layered application

Is it possible to do this in asp.net core, if yes HOW?

0

There are 0 best solutions below