Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/masastack/MASA.Framework/llms.txt

Use this file to discover all available pages before exploring further.

MASA Framework is designed around a strict two-layer package architecture that separates technology-agnostic abstractions from concrete implementations. This design lets you build your domain and application layers against stable interfaces while swapping the underlying infrastructure providers freely — often with a single line change in Program.cs.

The Two-Layer Design

Every capability is split across two NuGet package families:
Masa.BuildingBlocks.<Category>   ← interfaces, base classes, contracts
Masa.Contrib.<Category>          ← concrete implementations, DI registrations
BuildingBlocks packages contain only pure C# abstractions: interfaces (e.g. IEventBus, IDistributedCacheClient), base classes (e.g. ServiceBase, Event), and data contracts. They carry zero framework-specific dependencies and are safe to reference from domain libraries. Contrib packages contain the real implementations backed by specific technologies (Redis, SQL Server, Dapr, etc.). Each Contrib package includes its own ServiceCollectionExtensions with Add* methods that register the implementation under the corresponding BuildingBlocks interface.
Your domain and application projects should reference only Masa.BuildingBlocks.*. Only your composition root (typically Program.cs or the host project) needs to reference Masa.Contrib.* packages.

Swapping Implementations

Because all service code depends on Masa.BuildingBlocks abstractions, switching a provider means:
  1. Remove the old Masa.Contrib.* NuGet package.
  2. Add the new Masa.Contrib.* NuGet package.
  3. Change the Add* call in Program.cs.
No domain or application code changes are required.
// Switch from SQL Server to PostgreSQL:
// Before:
// builder.Services.UseSqlServer<OrderDbContext>(connectionString);
// After:
builder.Services.UseNpgsql<OrderDbContext>(connectionString);

MasaApp — The Global Service Locator

MasaApp (in Masa.BuildingBlocks.Data) is the static global service locator used internally throughout the framework. It bridges the gap between the static extension-method entry points and the DI container. Key members:
MemberDescription
MasaApp.GetAssemblies()Returns the global assembly list used for scanning. Falls back to AppDomain.CurrentDomain.GetAssemblies() if not explicitly set.
MasaApp.SetAssemblies(params Assembly[])Override the assembly list (useful in unit tests or modular monoliths).
MasaApp.TrySetAssemblies(...)Set only if not already assigned.
MasaApp.GetRequiredService<T>()Resolve a service from the root IServiceProvider.
MasaApp.GetService<T>()Nullable variant of GetRequiredService<T>().
MasaApp.Build(IServiceProvider)Captures the built IServiceProvider as the root provider.
MasaApp.GetServices()Returns the global IServiceCollection reference.
// Explicitly scope assembly scanning to your own assemblies
MasaApp.SetAssemblies(
    typeof(Program).Assembly,
    typeof(OrderService).Assembly
);
MasaApp.GetRequiredService<T>() resolves from the root provider, not the current HTTP request scope. Avoid using it to resolve scoped services; prefer injecting them through constructor or Minimal API parameter binding.

Assembly Scanning

MASA Framework building blocks discover handlers, services, and other convention-based types through automatic assembly scanning at startup. All scanning goes through MasaApp.GetAssemblies(), so the framework always operates on a consistent, configurable assembly list.
services.AddEventBus() calls MasaApp.GetAssemblies() to obtain all assemblies, then uses DefaultDispatchNetworkProvider to reflect over every public type and method. Methods decorated with [EventHandler] are compiled into a dispatch network (a directed graph from event type to ordered handler list). The handler types are then registered in DI at ServiceLifetime.Scoped.
// Default: scans MasaApp.GetAssemblies()
services.AddEventBus();

// Explicit assembly list:
services.AddEventBus(new[] { typeof(OrderCommandHandler).Assembly });
builder.AddServices() scans MasaApp.GetAssemblies() for all concrete types that inherit ServiceBase. Each discovered type is registered as a singleton in DI, and its Type is appended to GlobalMinimalApiOptions.ServiceTypes. Later, app.MapMasaMinimalAPIs() iterates that list, resolves each ServiceBase instance, and calls AutoMapRoute() to register endpoints with the ASP.NET Core router.

Building Blocks Reference

The following table lists every building block shipped in Masa.BuildingBlocks:
CategoryPackageKey Abstraction
CachingMasa.BuildingBlocks.CachingIDistributedCacheClient, IMultilevelCacheClient
ConfigurationMasa.BuildingBlocks.ConfigurationIConfigurationApiClient
DDD — DomainMasa.BuildingBlocks.Ddd.DomainIAggregateRoot, IDomainEventBus, IRepository<>
EventBusMasa.BuildingBlocks.Dispatcher.EventsIEventBus, IEvent, IEventHandler<>
Integration EventsMasa.BuildingBlocks.Dispatcher.IntegrationEventsIIntegrationEventBus, IIntegrationEvent
Minimal APIsMasa.BuildingBlocks.Service.MinimalAPIsServiceBase, IService
CallerMasa.BuildingBlocks.Service.CallerICaller, ICallerFactory
IsolationMasa.BuildingBlocks.IsolationIMultiTenantContext, IMultiEnvironmentContext
CQRSMasa.BuildingBlocks.ReadWriteSplitting.CqrsICommand, IQuery<>, IQueryHandler<,>
Event SourcingMasa.BuildingBlocks.ReadWriteSplitting.EventSourcingIEventSourceRepository<>
Object StorageMasa.BuildingBlocks.Storage.ObjectStorageIClient (object storage)
Background JobsMasa.BuildingBlocks.Extensions.BackgroundJobsIBackgroundJobManager
Rules EngineMasa.BuildingBlocks.RulesEngineIRulesEngineClient
Search / AutoCompleteMasa.BuildingBlocks.SearchEngine.AutoCompleteIAutoCompleteClient
Globalization / I18nMasa.BuildingBlocks.Globalization.I18nII18n, I18n<>

Contrib Implementations Reference

Each Masa.Contrib.* package registers its implementation under the matching Masa.BuildingBlocks interface. The table below maps building blocks to their available Contrib providers:
Building BlockContrib PackageTechnology
Distributed CacheMasa.Contrib.Caching.Distributed.StackExchangeRedisRedis via StackExchange.Redis
Multilevel CacheMasa.Contrib.Caching.MultilevelCacheIn-process + distributed hybrid
ConfigurationMasa.Contrib.ConfigurationMicrosoft.Extensions.Configuration
Configuration (DCC)Masa.Contrib.Configuration.ConfigurationApi.DccMASA DCC remote config
EF Core (SQL Server)Masa.Contrib.Data.EFCore.SqlServerSQL Server
EF Core (PostgreSQL)Masa.Contrib.Data.EFCore.PostgreSqlPostgreSQL
EF Core (MySQL)Masa.Contrib.Data.EFCore.MySql / Masa.Contrib.Data.EFCore.Pomelo.MySqlMySQL / MariaDB
EF Core (SQLite)Masa.Contrib.Data.EFCore.SqliteSQLite
EF Core (Oracle)Masa.Contrib.Data.EFCore.OracleOracle
EF Core (Cosmos)Masa.Contrib.Data.EFCore.CosmosAzure Cosmos DB
EF Core (In-Memory)Masa.Contrib.Data.EFCore.InMemoryIn-memory (testing)
DDD DomainMasa.Contrib.Ddd.DomainCore domain services
DDD RepositoryMasa.Contrib.Ddd.Domain.Repository.EFCoreEF Core repository impl
EventBusMasa.Contrib.Dispatcher.EventsIn-process local dispatcher
Integration EventsMasa.Contrib.Dispatcher.IntegrationEventsTransactional outbox base
Integration Events (Dapr)Masa.Contrib.Dispatcher.IntegrationEvents.DaprDapr pub/sub
Integration Event LogsMasa.Contrib.Dispatcher.IntegrationEvents.EventLogs.EFCoreEF Core outbox log
Minimal APIsMasa.Contrib.Service.MinimalAPIsASP.NET Core Minimal APIs
Caller (HTTP)Masa.Contrib.Service.Caller.HttpClientHttpClient-based
Caller (Dapr)Masa.Contrib.Service.Caller.DaprClientDapr service invocation
IsolationMasa.Contrib.IsolationCore isolation middleware
Isolation (Multi-Tenant)Masa.Contrib.Isolation.MultiTenantTenant resolution
Isolation (Multi-Env)Masa.Contrib.Isolation.MultiEnvironmentEnvironment resolution
CQRSMasa.Contrib.ReadWriteSplitting.CqrsCQRS scaffolding
Object StorageMasa.Contrib.Storage.ObjectStorageBase object storage
Background Jobs (Memory)Masa.Contrib.Extensions.BackgroundJobs.MemoryIn-memory (dev/testing)
Background Jobs (Hangfire)Masa.Contrib.Extensions.BackgroundJobs.HangfireHangfire
Rules EngineMasa.Contrib.RulesEngine.MicrosoftRulesEngineMicrosoft RulesEngine
I18nMasa.Contrib.Globalization.I18nJSON resource files
I18n (ASP.NET Core)Masa.Contrib.Globalization.I18n.AspNetCoreRequest culture middleware
I18n (DCC)Masa.Contrib.Globalization.I18n.DccMASA DCC remote i18n

How Building Blocks Compose

The diagram below shows the dependency flow for a typical microservice:
┌──────────────────────────────────────────────┐
│              Your Application Code           │
│  (depends on Masa.BuildingBlocks.* only)     │
└────────────────────┬─────────────────────────┘
                     │ references interfaces

┌──────────────────────────────────────────────┐
│           Masa.BuildingBlocks.*              │
│  IEventBus, ServiceBase, IRepository<>, …   │
└────────────────────▲─────────────────────────┘
                     │ implements
┌──────────────────────────────────────────────┐
│              Masa.Contrib.*                  │
│  EventBus, MinimalAPIs, EFCore.SqlServer, …  │
│  (registered in Program.cs / host)           │
└──────────────────────────────────────────────┘
The composition root (Program.cs) is the only place that knows which Contrib packages are used. Every other project in the solution stays fully decoupled from infrastructure choices.

Explore Building Blocks

Quickstart

See a working Program.cs, ServiceBase, and EventHandler wired together end-to-end.

Introduction

Overview of MASA Framework’s goals, package conventions, and MIT license.

Event Bus

Publish and handle in-process events with middleware, retry, and saga support.

DDD Overview

Aggregates, domain events, and EF Core repositories for DDD architectures.

Build docs developers (and LLMs) love