Get a Head Start Developing Multitenant SaaS Cloud Applications Using ASP.NET Core and Microsoft Azure
Tags: dotnet, csharp, productivity
Published: 2020-01-23 10:01:09

---
title: Get a Head Start Developing Multitenant SaaS Cloud Applications Using ASP.NET Core and Microsoft Azure
published: true
date: 2020-01-22 11:30:51 UTC
tags: dotnet, csharp, productivity
canonical_url: https://www.syncfusion.com/blogs/post/get-a-head-start-developing-multitenant-saas-cloud-applications-using-asp-net-core-and-microsoft-azure.aspx
cover_image: https://www.syncfusion.com/blogs/wp-content/uploads/2020/01/Multitenant-SaaS-application-672x372.png
---

The next revolution in the software industry will be [SaaS](https://en.wikipedia.org/wiki/Software_as_a_service) cloud-based applications. In 2020, you will see many SaaS applications coming out on the market. Nowadays, there are many technologies available that make building SaaS applications easier. The recent release of the cross-platform [ASP.NET Core 3.1](https://docs.microsoft.com/en-us/aspnet/core/), which is battle-tested and performs on par with other technologies, is an ideal choice to build a SaaS application if you are already familiar with .NET.

In this post, you will find some useful tips and libraries that will help you get a head start on your SaaS application using ASP.NET Core and Azure.

## Setting up a project structure

First, to start your application, set up a project structure. There are some good projects and architectural references that I listed in my [previous blog](https://dev.to/karthickramasamy08/awesome-list-of-top-asp-net-core-based-open-source-application-projects-24d1-temp-slug-6256439). Some top project templates to look at when starting a project are:

- [Dotnet-Boxed](https://github.com/Dotnet-Boxed/Templates)
- [CleanArchitecture](https://github.com/JasonGT/CleanArchitecture)
- [Angular starter-kit](https://github.com/ngx-rocket/starter-kit)

Also, I suggest watching this [video](https://www.youtube.com/watch?v=5OtUm1BLmG0) on clean architecture by Jason Taylor.

## Multitenancy

The next important step in building a SaaS application is to handle multitenancy, the serving of multiple tenants using a single instance of an application. To handle multitenancy, there are several open-source libraries available that will provide boilerplate code. Some of the top libraries in this category are:

- [saaskit](https://github.com/saaskit/saaskit)
- [MultiTenant](https://github.com/Finbuckle/Finbuckle.MultiTenant)
- [cloudscribe](https://github.com/cloudscribe/cloudscribe)
- [OrchardCore](https://github.com/OrchardCMS/OrchardCore)
- [aspnetboilerplate](https://aspnetboilerplate.com/Pages/Documents/Multi-Tenancy)

You can also check out blog posts on multitenancy by [Ben Foster](https://benfoster.io/blog/tagged/saaskit) or [Gunnar Peipman](https://gunnarpeipman.com/series/multi-tenant-aspnet-core/). These blogs will help you in setting up multitenancy in your project.

## Error logging

Error logging is also one of the important things to include in your project. There are several open-source libraries available, some of the top libraries in this category are:

- [Exceptionless](https://exceptionless.com/)
- [NLog](https://github.com/NLog/NLog)
- [Serilog](https://github.com/serilog/serilog)

## Health checks

Health checks are used to monitor an application. When you are developing a system with microservice architecture, this is one of the important things to consider. ASP.NET Core provides inbuilt health check options, and if you need a UI for monitoring the health of your microservices, then check out this library [AspNetCore.Diagnostics.HealthChecks](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks).

## Authentication

ASP.NET Core now ships with IdenityServer4. This library provides most authentication-related functionalities. Check out this project, [JPProject.IdentityServer4.AdminUI](https://github.com/brunohbrito/JPProject.IdentityServer4.AdminUI), which demonstrates many features of identity server. Also, you can check out blog posts by [Scott Brady](https://www.scottbrady91.com/), as he writes useful, informative posts about Identity Server.

## Authorization

Authorization is important in an application. There are different types of authorization techniques:

- Role-based authorization
- Policy-based authorization

Based on your application, select the one that best suits your needs. I recommend you check out this blog post on a [better way to handle authorization in ASP.NET Core](https://www.thereformedprogrammer.net/a-better-way-to-handle-asp-net-core-authorization-six-months-on/).

## Feature management

In a SaaS application, you may have different pricing plans for products. Depending on the pricing plan, some features will be shown or hidden. Microsoft Feature Management is handy for implementing pricing plan-based features. Check out blogs by [Andrew Lock](https://andrewlock.net/introducing-the-microsoft-featuremanagement-library-adding-feature-flags-to-an-asp-net-core-app-part-1/) related to [Microsoft.FeatureManagement](https://github.com/microsoft/FeatureManagement-Dotnet).

## Security

Web applications are prone to vulnerabilities, so you must pay attention to the security of your application by adding strong authentication, authorization, encryption, and security headers. Some informative posts and resources related to security are:

- [OWASP CheatSheetSeries](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/DotNet_Security_Cheat_Sheet.md)
- [Damien Bod](https://damienbod.com/2018/02/08/adding-http-headers-to-improve-security-in-an-asp-net-mvc-core-application/)
- [Karthick](https://dev.to/syncfusion/10-best-practices-to-secure-asp-net-core-mvc-web-applications-5c31)

## Validation

ASP.NET Core provides built-in attribute-based validations. But if you need a cleaner way to write validation, then do check out the  [Fluent Validation](https://fluentvalidation.net/) library.

## Caching

Caching helps in improving the performance of an application and is one of the areas that needs to be considered, especially in a multitenant application. There are two types of caching:

- In-memory caching
- Distributed caching—Redis is preferred for SaaS applications

If you are using Redis for caching, then this library will help you: [StackExchange.Redis](https://github.com/StackExchange/StackExchange.Redis).

## Microservice communication

In microservices, there needs to be reliable intercommunication among APIs. There are two types of communication:

- HTTP-based
- gRPC

If you are using HTTP-based communication, then check out the [Polly](https://github.com/App-vNext/Polly) library.

## API gateway and reverse proxy

In microservice applications, you will need an API gateway to serve as a front-end for the back-end. Two popular libraries are:

- [Ocelot](https://github.com/ThreeMammals/Ocelot)
- [ProxyKit](https://github.com/proxykit/ProxyKit)

You can also use Ngnix or the Azure API gateway for this purpose.

## Documentation

There are several libraries available for documentation. Some of the top open-source libraries in this category are:

- [AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore)
- [redoc](https://github.com/Redocly/redoc)
- [docsify](https://github.com/docsifyjs/docsify)

## Scheduler

To run background jobs for your application, there are some good libraries:

- [Quartz](https://github.com/quartznet/quartznet)
- [Hangfire](https://github.com/HangfireIO/Hangfire/)

You can also build background jobs using .NET Core Worker services and host in Azure as a Web Jobs.

## Testing

Automated testing is one of the important areas to consider. There are different types of automated testing available:

- [Unit testing](https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/testing?view=aspnetcore-3.1)
- Functional testing
- [Integration testing](https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-3.1)

In Entity Framework Core, an in-memory database was introduced that helps make testing for database logics easier without the overhead of actual database operations.

There are some good libraries available that will help you in writing unit testing:

- [moq](https://github.com/moq/moq)
- [NSubstitute](https://nsubstitute.github.io/)
- [AutoFixture](https://github.com/AutoFixture/AutoFixture)
- [fluentassertions](https://github.com/fluentassertions/fluentassertions)

**A few more useful libraries:**

- [MediatR](https://github.com/jbogard/MediatR)
- [NSwag](https://github.com/RicoSuter/NSwag)
- [AutoWrapper](https://github.com/proudmonkey/AutoWrapper)
- [NRules](https://github.com/NRules/NRules)
- [dynamic-linq-query-builder](https://github.com/castle-it/dynamic-linq-query-builder)
- [Dapper](https://github.com/StackExchange/Dapper)

## Code quality analyzers and linting

Code quality static analyzers tools help in writing code with proper standards and in maintaining quality. There are several open-source analyzers available in .NET Core. You can find the top 10 analyzers [in this article](https://medium.com/@bharatdwarkani/top-10-code-quality-static-analysers-for-asp-net-core-1660ad7a8d61). This process can be integrated in continuous integration using Cake Script.

## Front-end

Three popular front-end frameworks are Angular, React, and Vue. There is a long-running debate on which is better. In my opinion, Angular is good for building enterprise applications, even though it has a steep learning curve. Angular is a complete framework that has several functionalities built into its framework, unlike React or Vue. As I said, superiority is debatable based on your expertise and needs. You can choose any one of them and do well.

## Database

There are two popular databases available in Azure

- MS SQL—Elastic Pool
- Cosmo DB—NoSQL database

If you are going to use database-per-tenant architecture, then MS SQL Elastic Pool is a better choice. You can add up to 500 databases in one elastic pool, so it’s cost-effective. There are other storage models as well in SaaS, and which you choose depends on your application needs. A reference for other models can be found [on this Microsoft page](https://docs.microsoft.com/en-us/azure/sql-database/saas-tenancy-app-design-patterns#d-multi-tenant-app-with-database-per-tenant).

## Deployment

For deployment of an application, there are several options available. The best option is to deploy on the cloud, which allows you to scale, monitor, and load-balance your application. There are several ways to do this

- Deploy app in Azure App Service for Linux, containers, or Windows.
- Deploy app in Azure Kubernetes or Google Kubernetes.
- Deploy in VMs.

The simplest of all these is to deploy in the Azure App Service. You can find a guide on how to do that [in this article](https://medium.com/@bharatdwarkani/how-to-publish-asp-net-core-3-0-app-in-azure-linux-app-service-explained-from-scratch-6e45392ca256). Azure App Service supports scaling up to 20 instances with its Traffic Manager. If your app needs more scaling options, then Kubernetes is best.

## Azure service

There are several Azure services available for SaaS application development. Some of the most commonly used services are:

- [App Service](https://azure.microsoft.com/services/app-service): Managed hosting platform for deploying and scaling applications.
- [Azure SQL Database](https://azure.microsoft.com/services/sql-database/): Managed SQL database as a service.
- [Azure Cosmos DB](https://azure.microsoft.com/services/cosmos-db/): Globally distributed, multimodel database service for any scale. It also provides single-digit millisecond latency for read and write.
- [Azure Cache for Redis](https://azure.microsoft.com/services/cache/): Managed Redis cache.
- [Azure Functions](https://azure.microsoft.com/services/functions/): A managed service to run serverless, event-driven or trigger-based workloads.
- [Service Bus](https://azure.microsoft.com/services/service-bus/): Scalable managed service providing reliable queuing and a publish/subscribe messaging service. Useful for handling loads at scale in distributed systems.
- [Event Grid](https://azure.microsoft.com/services/event-grid/): Managed event routing service using publish/subscribe model. Useful for event-driven microservices.
- [Azure Blob Storage](https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blobs-introduction): For all kinds of file storage needs.
- [Logic Apps](https://azure.microsoft.com/services/logic-apps/): Out-of-the-box logic connectors for integration. Can be integrated with Event Grid or Service Bus for logical routing of messages.
- [Application Gateway](https://azure.microsoft.com/services/application-gateway/): A load balancer supporting SSL termination, cookie-based authentication, and a round-robin load balancer.
- [Azure Kubernetes Service](https://azure.microsoft.com/services/kubernetes-service/): An orchestrator for containerized applications.
- [Azure Search](https://azure.microsoft.com/services/search/): Full-text search service.
- [Azure Synapse Analytics](https://azure.microsoft.com/services/synapse-analytics/): Data warehouse to process complex queries.
- [Azure DevOps](https://azure.microsoft.com/services/devops/): A cloud service for continuous integration and deployment.

A directory of Azure Services can be found [on the Azure site](https://azure.microsoft.com/en-in/services/).

## Conclusion

I hope these tips and libraries will help you get a head start on your SaaS application. You can also check out the [Azure Application Architecture Guide](https://docs.microsoft.com/en-us/azure/architecture/guide/).

Syncfusion also provides several controls for Angular, React, Vue, and ASP.NET Core that will further ease your development of a SaaS application. For example, Syncfusion provides 70+ high-performance, lightweight, modular, and responsive [ASP.NET Core UI controls](https://www.syncfusion.com/aspnet-core-ui-controls) such as [DataGrid](https://www.syncfusion.com/aspnet-core-ui-controls/grid), [Charts](https://www.syncfusion.com/aspnet-core-ui-controls/charts), and [Scheduler](https://www.syncfusion.com/aspnet-core-ui-controls/scheduler). You can use them to improve your application development.

Please share your feedback in the comments section. You can also contact us through our [support forum](https://www.syncfusion.com/forums), [Direct-Trac](https://www.syncfusion.com/account/login), or [feedback portal](https://www.syncfusion.com/feedback). We are waiting to hear your feedback!

The post [Get a Head Start Developing Multitenant SaaS Cloud Applications Using ASP.NET Core and Microsoft Azure](https://www.syncfusion.com/blogs/post/get-a-head-start-developing-multitenant-saas-cloud-applications-using-asp-net-core-and-microsoft-azure.aspx) appeared first on [Syncfusion Blogs](https://www.syncfusion.com/blogs).