
Design a dotnet multi-tenant web api with a root tenant that administers others, while tenants manage their own data using per-tenant or shared databases with role-based permissions via asp.net identity.
design a multi-tenant web api with swagger ui, role based permissions, and json web tokens. present tenant onboarding and a blazor webassembly front end with per-tenant or shared database strategies.
Develop a Blazor WebAssembly frontend for a multi-tenant application, integrating tenant management, subscription control, dynamic user and role permissions, and authentication and authorization in the UI.
Install Microsoft SQL Server and the management studio to visualize and query your databases, with SQL Server as the default database. You may also use Postgres by adjusting the code, and set up Visual Studio 2022 or Visual Studio Code with the provided download URLs.
Summarizes project responsibilities in clean architecture: define domain entities in the domain layer, implement CRUD in the application layer, and manage infrastructure with Entity Framework Core and a web API.
Install and configure multi-tenant infrastructure by adding the buckle multi-tenant package, asp.net core, and entity framework core packages via NuGet, then set up identity, sql server provider, and ef tools.
Define a tenant entity model implementing tenant info, including identity, identifier, name, and connection string. Include admin email and is active flag with subscription status for dedicated or shared databases.
Create a tenant db context for ABC school, inheriting from the multi-tenant DB context, configuring the tenants table and multi-tenancy schema, and planning to replace magic strings with constants.
Define tenancy constants to replace magic strings, exposing a public tenant ID name. Integrate these constants in startup and the db context, and plan future schema constants and migrations.
Create ApplicationRole and ApplicationRoleClaim by extending IdentityRole and IdentityRoleClaim, add descriptions, and group permissions for administrators, management, HR, and academics in a multi-tenant .NET app.
Define the application DbContext by inheriting from the base DbContext, add the schools DbSet, and register it in startup via dependency injection with SQL Server and a shared connection string.
Configure entity type configurations to customize ASP.NET Identity tables, changing their names and schema, and enable multi-tenant data isolation by adding tenant-aware columns.
Override on model creating in the base db context and apply configuration from the executing assembly to load all entity type configurations, including the school entity in the academics schema.
Expose read-only school permissions and filter by root, admin, and basic categories to assign correct rights within a multi-tenant application.
Seed the default roles from predefined constants, create any that do not exist using the role manager, and prepare to assign permissions.
Seed the root tenant admin by defining constants for default password and admin first and last name, then create and hash the user via the multi-tenant context and user manager.
Define and seed a tenant database for a multi-tenant app, implementing a tenant db setup, interface, and async data initialization. Inject dependencies and seed tenant data before identity data.
Initialize the database with a root tenant by checking for an existing root, creating the root tenant using predefined constants, and saving changes via the tenant context and cancellation token.
Learn to seed tenant and application databases via dependency injection, wire as transient services, and invoke an async database initializer in startup.
define and raise custom unauthorized exceptions in the application layer with status code 401, and handle them via a global exception handling middleware during login.
Implement non-generic failure response wrappers with three overloads: single message, list of messages, and synchronous and asynchronous variants, each setting isSuccessful to false for failed requests.
Explore building non-generic and generic response wrappers for success scenarios, including synchronous and asynchronous overloads with single or multiple messages and proper flag handling.
Define and implement a generic response wrapper in a single file, including a public class ResponseWrapper<T> with data, and synchronous and asynchronous success and failure methods that fulfill the contract.
Define a permission policy provider to dynamically create authorization policies for specific permissions, using token claims prefixed with 'permission' to evaluate access.
Implement a login feature that accepts a username and password, generates a json web token, and returns a token response with the jwt, a refresh token, and its expiry date.
Implement the token service in the infrastructure layer, wiring in the user manager and multi-tenant context to support login and refresh token flows using jwt.
Implement an asynchronous login with multi-tenant validations: verify active tenant, confirm user exists in that tenant, check password, and ensure the user is active before authenticating.
Implement token service login validation by checking non-root tenants' subscription expiry using valid up to dates; throw an authorization exception if expired, while root tenants bypass expiry checks.
Learn to implement refresh tokens by creating a claims principal extensions class that exposes access to user information such as email, user id, and tenant details from the current context.
Implement a complete refresh token flow: validate the expiring token, verify signing key and claims, locate the user by email, validate and update refresh token, and generate a new token.
Create a JWT settings class in the application layer to hold the secret, token expiry in minutes, and refresh token expiry in days, replacing magic strings with configuration.
Learn how to refactor configuration into dependency injection by creating a public extension that binds JWT settings from app settings and registers them in the program startup.
Register a json web token service in dependency injection, configure jwt bearer authentication, and handle authentication events to return consistent, wrapped error responses via a global response wrapper.
Implement jwt authentication into dependency injection, handle on challenge responses, set unauthorized and forbidden results, and add authorization overloads to secure endpoints.
Register JWT authentication in dependency injection, dynamically create in-memory policies from constant permissions, and wire the JWT service in program to enable login and token-based access.
Install the swagger package, create an Open API swagger header, and implement a tenant header attribute inheriting the swagger header to pass the tenant in the login request header.
Explore dynamic Swagger documentation by adding Swagger settings drawn from configuration, including the API title, company name, license, contact number, and email address, and extend the Swagger UI accordingly.
Implement a swagger header attribute processor to evaluate the tenant header, process metadata in the header, identify swagger headers, and update open api parameters with a string tenant value.
Remove the default swagger UI and endpoint explorer from program.cs, replace with add OpenAPI document, and remove JWT middleware in favor of infrastructure authentication and authorization middlewares after multi-tenant setup.
Define a permission-based authorize attribute to protect endpoints by generating permissions from feature and action, then apply the attribute and test policy-based authorization.
Test the post authorize attribute in api testing using swagger, open api extensions, and the authorization header to attach tokens and inspect authorized versus unauthorized responses.
Enable user login in the application layer using CQRS with mediator. Install mediator, Map Star, fluent validation, and the dependency injection extension to map requests and validate inputs.
Configure dependency injection in the application layer by creating a startup class, registering validators from the assembly, and wiring mediator with services in the web api program.
Define and implement a get token query using mediator, token request, and token service to generate a token and refresh token, using a response wrapper for multi-tenant .NET full-stack apps.
Design a base api controller that injects a mediator sender to dispatch commands and queries, using dependency injection and http context to resolve the required services.
Test the login endpoint by using root tenant, username, and password from constants. Retrieve the JWT and inspect its payload for name identifier, email, name, tenant, role, and permissions.
Test protected endpoints by validating token-based authentication and read permissions like school read, using a weather forecast endpoint to confirm authorization and successful 200 responses.
Learn to handle expired JSON web tokens by guarding response modification with a has started check, returning unauthorized and a token expired message; replicate by shortening token lifespan.
Implement a global error handling middleware for a web api that catches all exceptions and returns a json error with a message and proper status code.
Dive deep into .NET 8 with our advanced online course, focusing on multi-tenancy solutions and cutting-edge techniques. Learn to architect clean and scalable solutions while mastering multi-tenancy support using Finbuckle libraries. Explore subscription management for tenants, ASP.NET Core Identity for user management, and JWT authentication for secure access control.
Unlock the power of permission-based authorization and seamlessly implement global response wrappers for standardized API responses. Delve into advanced patterns such as CQRS with MediatR, Pipeline behaviours and leverage FluentValidation for robust data validation. Discover the elegance of C# 9's primary constructor syntax and elevate your API documentation with advanced Swagger UI implementations.
Ideal for developers seeking to enhance their ASP.NET Core skills, this course offers practical insights and hands-on experience to excel in building sophisticated, multi-tenant applications.
Key Topics Covered:
Multi-Tenancy Support with Finbuckle
Subscription Management for Tenants
ASP.NET Core Identity and JWT Authentication
Permission-Based Authorization
Global Response Wrapper Implementation
CQRS Patterns with MediatR
Data Validation using FluentValidation
Primary Constructor Syntax in C# 9
Advanced Swagger UI Implementations
Blazor Webassembly
MudBlazor UI Library
And much more...
Prerequisites: Basic understanding of ASP.NET Core development and C# programming language recommended.
Enroll now and unlock the full potential of ASP.NET Core for multi-tenant applications!