dazinator / Dotnettency

Mutlitenancy for dotnet applications
MIT License
111 stars 23 forks source link

Distinguish by other then uri, like headers or claims #42

Closed nmocruz closed 5 years ago

nmocruz commented 5 years ago

I was digging to see how to make the tenant resolution be based on header or claims, (maybe is not a good way to do the multitenancy). I I thought that was possible to extend HttpContextTenantDistinguisherFactory and register ITenantDistinguisherFactory, maybe the TenantDistinguisher is based on Uri, can this be extended?

dazinator commented 5 years ago

You are on the right path. Have a look at the cookies example here: https://github.com/dazinator/Dotnettency.Samples/tree/aspnetcore20/src/Sample.CustomTenantDistinguisher

Basically the "distinguisher" (bad name I know) would insoect the request (headers, claims etc) then come up with an identifier as to which tenant it is, which it returns as a URI of your choice. For example: "tenant://foo". Then look at the shell factory class in that sample project. It is responsible for initialising a tenant identified by the Uri.The uri is used as a cache key for the tenant and the shell factory wont be called if the tenant with that uri has already been initialised once before.

nmocruz commented 5 years ago

@dazinator Ok, I got it, I was kind of blocked by seeing complex type when I wanted to pass a string or other thing to represent the tenantId. My first idea was to extend TenantDistinguisher class, and so I miss a TenantDistinguisher<TKey> where I could extend usingTenantDistinguisher<string>, but your suggestion is good enough.

nmocruz commented 5 years ago

You can close this if you want, BTW I was also trying to use modules per tenant. I notice that you have also support for this, but I saw a dependency on structuremap it possible to make it ioc frameworks agnostic?

dazinator commented 5 years ago

Thats on my to do list for the future!