question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add Identity to StoreDbContext

See original GitHub issue

I’m trying to add Identity to StoreDbContext and I get error in IdentityDbContext, can’t accept class

    public class MultiTenantStoreDbContext : EFCoreStoreDbContext<ClientTenantInfo>, IdentityDbContext<ApplicationUser, ApplicationRole, string>
    {
        public MultiTenantStoreDbContext(DbContextOptions<MultiTenantStoreDbContext> options) : base(options)
        {
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            new TenantInfoConfiguration(modelBuilder.Entity<ClientTenantInfo>());
            base.OnModelCreating(modelBuilder);
        }

        public DbSet<ClientTenantInfo> ClientTenantInfos { get; set; }
    }

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
goforebrokecommented, Jan 18, 2022

Andrew,

I made the changes you suggested and this is what I came up with and so far and its working.

In my extension class called from startup

// Add Tenant Services
services.AddMultiTenant<MyTenantInfo>()
.WithStore<AppStoreDbContext>(ServiceLifetime.Scoped, new TenantInfo { ConnectionString = config.GetConnectionString("DefaultConnection")})
.WithRouteStrategy();

and I modified my constructor in the AppStoreDbContext class.

public AppStoreDbContext(ITenantInfo tenantInfo) : base(tenantInfo)
{
}

public AppStoreDbContext(ITenantInfo tenantInfo, DbContextOptions options) : base(tenantInfo, options)
{
}

I was able to create an initial migration, create the database with the tenant, identity, and my custom tables. I still need more testing, but so far the initial results are good. I will know more in the next few weeks. I will post back if I run into issues

Again thanks for your help and thx for making Finbuckle.

Jaime

1reaction
AndrewTriesToCodecommented, Oct 7, 2021

So this is trickier than I initially thought. I still plan to improve it but I recommend that if you want to make this work inherit from IMultiTenantStore<T> instead of EFCoreStoreDbContext<T> and register it using WithStore<T>. Then just implement the store methods yourself – basically copy from EFCoreStoreDbContext<T>. That way you can have your identity db context also be your tenant store. Good luck and let me know how it goes!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specifying correct context to add Identity into existing ...
I have an .Net Core 7 app using EFCore with some existing entities. Now that everything in there is tested and working, I'd...
Read more >
Identity model customization in ASP.NET Core
This article describes how to customize the underlying Entity Framework Core data model for ASP.NET Core Identity.
Read more >
Identity Setup and Configuration
Identity is built to use Entity Framework Core and store user information in a database. It comes with the class IdentityDbContext , which...
Read more >
Custom User Management in ASP.NET Core MVC ...
You can achieve this by right-clicking the project and Adding a new Scaffolded Item. On the dialog that appears, select the Identity and...
Read more >
Introducing Identity to the ASP.NET Core Project
In this article, we are going to learn how to integrate the ASP.NET Core Identity library in our existing project and add additional...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found