Multi tenant applications with K2BTools

There are many scenarios in which the application needs to have multi tenant support. Each application has its own requirements and data structures to model a multi tenant application. However most multi tenant applications should need

  1. When showing a list, the list should be automatically filtered by the tenant.
  2. When adding a record that is related to the tenant, the tenant should be set to the record in the business logic of the application.

K2BTools contemplates both.

Saving the current tenant

First of all K2BTools uses a K2BContext SDT to store Context information related to the user's session. Developers can add fields to the sdt. We recommend adding the tenant fields to this SDT.

Tenant Code in K2BContext SDT

In K2BTools there is a method called K2BSetContext. We recommend using this method (to set the context) after a successful login. K2BContext sdt is available in all web panels and transactions thar are generated or maintained by K2BTools patterns.
K2BSetContextCode should be added after login

Filtering data

To show data related to the current tenant only, developers can define a data selector and reference it in the"Universal Default Data Selector" property of K2BTools General Settings. The property references a Data Selector object that receives the K2BContext SDT as a parameter. The developer can write the appropriate condition. The data selector is used in all K2BTools pattern instances (in WorkWith, SubWorkWith, and Prompt nodes) unless the developer decides not to do so.

Data Selector Definition

Data Selector in General Settings

The application could have many transactions that are not related to the tenant. To tell K2BTools not to use the universal data selector in that instance there is a property called "Use Default Dataselector If Available" that can be set to "False".

Setting to false "use default data selector" property

Additionally for certain scenarios the developer can add to any K2BTools instance a DataSelector (node). Arguments can be added to this node, however K2BTools will always assume an implicit parameter that is the K2BContext SDT.

Adding data

Transaction rules can be added to assure that records inserted reference the current tenant. For this purpose, the Automatic rule generation using K2BTools can be used to generate rules that set the tenant to the corresponding attributes of the transaction.

Example of an automatic rule definition that sets the tenantcode and prevents the attribute from being edited