Finbuckle / Finbuckle.MultiTenant

Finbuckle.MultiTenant is an open-source multitenancy middleware library for .NET. It enables tenant resolution, per-tenant app behavior, and per-tenant data isolation.
https://www.finbuckle.com/multitenant
Apache License 2.0
1.26k stars 260 forks source link

Struggling with EF Core and Seeding data #851

Open MarkLFT opened 2 weeks ago

MarkLFT commented 2 weeks ago

I have spent the last four days trying to make an API multi-tenant. But am getting nowhere fast. I read the documentation and have read dozens of articles. It looked straightforward to use finbuckle with EF Core.

I am using configuration store and header plus static configuration. I am using database per tenant and using .net core 8 and DI.

Is there a working sample including seeding the database anywhere?

Most of the time I am getting null for the tenant in onconfiguring.

AndrewTriesToCode commented 2 weeks ago

Hi @MarkLFT

let me ask you a few questions to help.

1) db aside are things working as expected? For each request does the tenant resolution work ok?

2) are you seeing null tenant in the database during api requests, during your app startup/seeding, or both?

3) are you using migrations and if so are you seeing the issue there?

MarkLFT commented 2 weeks ago

Without finbuckle the api works correctly.

If I login to the api it seems to see be resolving correctly, bit as I can't get the seeding to work I have no user data in the dB I can't complete the login to test correctly.

My immediate issue is seeding the database. At the start if the seeding routine I am populating the assessor with a tenant, and that seems to work. But when I get a dB context the connection string is not getting loaded, unless I load it manually.

Then when the new user services are called, and it instantiates another dB context using DI the connection string is null again.

I am guessing using finbuckle with ef core, and seeding all the tenants is a very common scenario, so an upto date sample would be very useful.