Multi Tenant Solutions

Resolving the Tenant

Resolving the tenant can be done in several ways:

  • Using a selctor and storing its identifier in a cookie, which is read at the beginning of each request
  • Using a path on the Url string that is the identifier, which is extracted from the url at the beginning of each request
  • Using a hostname, which is resolved at the beginning of each request.

For our point-of-sale solution, we chose the hostname approach. For our use-case, this gave each client their own “home” from a UI perspective, which felt to be the best approach. Here is the base code to perform tenant resolution. The basics here are that we resolve the tenant id from the hostname, and use it as the key for performing a lookup in the database to get the connection information to the client’s database:

Within several other portions of our system, such as the service where each store would connect to our server environment, we needed a standard connection url to make configuration easier for VARs and clients alike. For these instances, we resolve the current claims principal from the request’s context, and extract out their tenant id from its claim. Once we have that identifier, we can then build the connection to the database.