0

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?

DK_bhai
  • 337
  • 3
  • 14
  • The link you have shared, have you tried that? What the issue you are having with could you please share? – Md Farid Uddin Kiron May 09 '23 at 09:55
  • In that post the accepted answer is using ```Microsoft.AspNet.Identity.EntityFramework``` in data layer which does not answer my question. I want to know if I can decouple identity from data layer & if not I need a concert reasoning, as it makes the data layer restricted for MVC applications which are using Identity, thus reducing reusability. – DK_bhai May 09 '23 at 10:01

0 Answers0