Multi Tenant Solutions

Isolating the Business Logic

With the facades over the connection built in a reliable manner, the next step is to encapsulate the business logic in a series of services. By doing so, we can reuse this same logic for web applications, client applications, as well as mobile applications.

Services have no rhyme or reason in format. The idea here is to create an interface, along with utilizing Criteria and Presentation Model objects for shuttling data in and out of the service. This separates the OR/M code from our overall business logic. Ultimately, when we get to the point of authoring unit tests, we will also be able to mock the IRepository<T> interfaces and return real Presentation Models for assertions.

Here is an example of a basic service:

The use of the above service is to allow access to each client’s account and assist in provisioning it. The overall take away from this is two fold:

  1. That the service uses Inversion-of-Control techniques to provide dependencies via the implementation’s constructor, therefore allowing for easy unit-testing
  2. The basis of the business logic for adjusting accounts within the system is encapsulated in a manner where the code can be used within a web, desktop, or mobile application.