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.33k stars 265 forks source link

How to use Finbuckle with Identity and EntityFramework in Asp.net #418

Closed shreya-groot closed 3 years ago

shreya-groot commented 3 years ago

Please provide some example to do this as I am finding this doc at this url: https://github.com/Finbuckle/Finbuckle.MultiTenant/tree/main/samples/ASP.NET%20Core%203/IdentityDataIsolationSample

quite messy.

please help

AndrewTriesToCode commented 3 years ago

hi @shreya-groot

I agree the sample isn't a good as it could be -- it tries to show a few different things.

Let me ask you a few questions and I'll give you some specific advice:

  1. are you using a shared database or separate databases per tenant?
  2. which multitenant strategy are you using?
  3. are you using the default Identity UI?
  4. do you have multiple db context classes? 1 for Identity and 1 for the rest of the app? Or do you have a single shared db context?

Any other specific problems you are running into?

shreya-groot commented 3 years ago

Hello Andrew, I am having problem to implement Finbuckle as I am having following specifications in it:

  1. I am using Identity in Asp.Net 2.I am having one database that has be shared among all tenenat
  2. I need to filter data corresponding to particular tenant by queries

Please guide me Thanks & Regards Shreya

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: Andrew @.> Sent: 20 April 2021 08:55 To: @.> Cc: @.>; @.> Subject: Re: [Finbuckle/Finbuckle.MultiTenant] How to use Finbuckle with Identity and EntityFramework in Asp.net (#418)

hi @shreya-groothttps://github.com/shreya-groot

I agree the sample isn't a good as it could be -- it tries to show a few different things.

Let me ask you a few questions and I'll give you some specific advice:

  1. are you using a shared database or separate databases per tenant?
  2. which multitenant strategy are you using?
  3. are you using the default Identity UI?
  4. do you have multiple db context classes? 1 for Identity and 1 for the rest of the app? Or do you have a single shared db context?

Any other specific problems you are running into?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/Finbuckle/Finbuckle.MultiTenant/issues/418#issuecomment-822944988, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASHXH4YVWH4LCXRB6L476LDTJTXY7ANCNFSM43CQO4OQ.

AndrewTriesToCode commented 3 years ago

@shreya-groot

in your app how do you detect the tenant? Does each tenant have a different url or hostname or do you do something completely different?

Before getting into the Identity MultiTenant Sample do you understand these samples?

  1. RouteStrategySample
  2. DataIsolationSample (not the Identity one -- this one shows the basics that Identity builds on)
shreya-groot commented 3 years ago

Actually I am allowing the user to login and I will use his AspNetUserId from that which I assume to be same as tenant id which has been inserted in tenant table while registering the user

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: Andrew @.> Sent: 20 April 2021 09:23 To: @.> Cc: @.>; @.> Subject: Re: [Finbuckle/Finbuckle.MultiTenant] How to use Finbuckle with Identity and EntityFramework in Asp.net (#418)

@shreya-groothttps://github.com/shreya-groot

in your app how do you detect the tenant? Does each tenant have a different url or hostname or do you do something completely different?

Before getting into the Identity MultiTenant Sample do you understand these samples?

  1. RouteStrategySample
  2. DataIsolationSample (not the Identity one -- this one shows the basics that Identity builds on)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/Finbuckle/Finbuckle.MultiTenant/issues/418#issuecomment-822953789, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASHXH445IRYIAQ2AHUFBF7LTJT3DPANCNFSM43CQO4OQ.

shreya-groot commented 3 years ago

And Also I don’t want to put tenant configuration in appSetting.json file as done in these two strategies

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: Andrew @.> Sent: 20 April 2021 09:23 To: @.> Cc: @.>; @.> Subject: Re: [Finbuckle/Finbuckle.MultiTenant] How to use Finbuckle with Identity and EntityFramework in Asp.net (#418)

@shreya-groothttps://github.com/shreya-groot

in your app how do you detect the tenant? Does each tenant have a different url or hostname or do you do something completely different?

Before getting into the Identity MultiTenant Sample do you understand these samples?

  1. RouteStrategySample
  2. DataIsolationSample (not the Identity one -- this one shows the basics that Identity builds on)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/Finbuckle/Finbuckle.MultiTenant/issues/418#issuecomment-822953789, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASHXH445IRYIAQ2AHUFBF7LTJT3DPANCNFSM43CQO4OQ.

shreya-groot commented 3 years ago

Please help me to create a Tenant when I am using Identity to let the user login inside my ASP.Net Core app

AndrewTriesToCode commented 3 years ago

@shreya-groot I'm sorry for the slow responses

You want to create a a tenant when a new user registers? Will your tenants have multiple users or will it be one user per one tenant?

You can create a new tenant by using the IMultiTenantStore<T>.TryAddAsync method which requires a TenantInfo object of type T. Not all of the stores implement this method though so you might have to create your own store.

Then when you need to create a new tenant you just create a new tenant object instance as required then call the TryAddAsync method on your IMultiTenantStore<T> store instance which you can get the store from the DI system in most cases.

shreya-groot commented 3 years ago

My tenant will have multiple users further. First of all I want to know which strategy I should use out of so many as I only want to create Tenant with so many users under him

In Asp.net core I have created all the users who can sign in into my application, but I want to make them specific to tenant, means I want to associate one tenant with each user without working on any routing.

please give me some example relateed to that.

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: Andrew @.> Sent: 28 April 2021 08:43 To: @.> Cc: @.>; @.> Subject: Re: [Finbuckle/Finbuckle.MultiTenant] How to use Finbuckle with Identity and EntityFramework in Asp.net (#418)

@shreya-groothttps://github.com/shreya-groot I'm sorry for the slow responses

You want to create a a tenant when a new user registers? Will your tenants have multiple users or will it be one user per one tenant?

You can create a new tenant by using the IMultiTenantStore.TryAddAsync method which requires a TenantInfo object of type T. Not all of the stores implement this method though so you might have to create your own store.

Then when you need to create a new tenant you just create a new tenant object instance as required then call the TryAddAsync method on your IMultiTenantStore store instance which you can get the store from the DI system in most cases.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/Finbuckle/Finbuckle.MultiTenant/issues/418#issuecomment-828109651, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASHXH45KYFFAMHPQM5NEZQTTK54OHANCNFSM43CQO4OQ.

AndrewTriesToCode commented 3 years ago

@shreya-groot it sounds like you are not using isolated Identity databases for each tenant and prefer to have a single Identity database where the tenant is associated with each user. In that case take a look at the "Shared Login" sample. It is ASP.NET 2.1 but the basic idea should still work. It will have a user login, check which tenant that user is, then use that tenant for all requests for that authorized user. No route or anything like that is needed.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

vasanth32 commented 1 year ago

@shreya-groot I too have similar requirement .. did you got any solution for it ?

jspitman commented 1 year ago

It would be really helpful to see and end to end solution. I keep seeing this question and none of the threads seem to resolve.

StefanRadosavljevic commented 1 year ago

I have same requirements :) Would love to see some solutions for this :)