Hybrid-tenancy with MongoDB in .NET API — Part 02

  • First, about the business rules: we will register many users in a different database, according to the register number of the company.
  • Second: all the data will store in MongoDB, so we will manipulate more than one database on it.
  • Third: we will build an API using .NET Core
  • Fourth and last: we will implement the tenancy technique in our project, according to request.
  • Interfaces: location where stay the contracts of repositories. Used to make the Dependency Injection.
  • Database: location where stay the repository classes.
  • Middleware: location where stay the code that intercepts the requests and makes something.
  • Models: location where stay the model entities

Model Entities

Tenant Configuration

  • SaasKit.Multitenancy v1.1.4 (or latest)
  • It is necessary to inherit the ITenantResolver interface and implement it.
  • This class will receive the intercept the request, verify the headers, get the header that contains the register number of the company, and attribute it to AppTenant class.

Database configurations and operations

  • MongoDB.Driver v2.11.5 (or latest)
  • In the constructor, we will wait for the MongoClient, to do the operations, database name e collection name, by Dependency Injection.
  • We will inherit the ICustomerRepository, to implement it and to do the Inversion of Control

The execution




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alex Alves

Alex Alves

Bachelor in Computer Science, MBA in Software Architecture and .NET Developer.