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?

2
  • The link you have shared, have you tried that? What the issue you are having with could you please share? Commented May 9, 2023 at 9: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. Commented May 9, 2023 at 10:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.