# Dependency Graph LiteBus is split into small packages so applications can reference only the modules they run. The graph has four layers: runtime, messaging, semantic modules, and optional infrastructure. ## Layer Map ```text Runtime.Abstractions -> Runtime -> Runtime.Extensions.Microsoft.DependencyInjection -> Runtime.Extensions.Autofac Messaging.Abstractions -> Messaging -> Messaging.Extensions.Microsoft.DependencyInjection -> Messaging.Extensions.Autofac Commands.Abstractions -> Commands Queries.Abstractions -> Queries Events.Abstractions -> Events Inbox.Abstractions -> Inbox -> Inbox.PostgreSql Outbox.Abstractions -> Outbox -> Outbox.PostgreSql LiteBus.PostgreSql -> shared PostgreSQL schema infrastructure for inbox/outbox stores Commands/Queries/Events/Inbox/Outbox depend on Messaging and Runtime.Abstractions. Storage packages depend on their abstraction package and the external store client. DI extension packages depend on the module package and the matching runtime adapter. ``` ## Package Table | Package | Role | Project dependencies | External dependencies | | --- | --- | --- | --- | | `LiteBus.Runtime.Abstractions` | DI-neutral service registration contracts | none | none | | `LiteBus.Runtime` | Default module registry and dependency descriptor handling | `Runtime.Abstractions` | none | | `LiteBus.Runtime.Extensions.Microsoft.DependencyInjection` | Microsoft DI adapter | `Runtime` | `Microsoft.Extensions.DependencyInjection.Abstractions` | | `LiteBus.Runtime.Extensions.Autofac` | Autofac adapter | `Runtime` | `Autofac` | | `LiteBus.Messaging.Abstractions` | Handler contracts, mediation contracts, execution context, storage contract interfaces | `Runtime.Abstractions` | none | | `LiteBus.Messaging` | Message registry, mediator, descriptor builders, default serializer, contract registry | `Messaging.Abstractions`, `Runtime.Abstractions` | `System.Text.Json` from the BCL | | `LiteBus.Commands.Abstractions` | Command contracts, command handlers, command mediation settings | `Messaging.Abstractions` | none | | `LiteBus.Commands` | Command mediator and command module | `Commands.Abstractions`, `Messaging`, `Runtime.Abstractions` | none | | `LiteBus.Queries.Abstractions` | Query contracts, stream query contracts, query handlers | `Messaging.Abstractions` | none | | `LiteBus.Queries` | Query mediator and query module | `Queries.Abstractions`, `Messaging`, `Runtime.Abstractions` | none | | `LiteBus.Events.Abstractions` | Event contracts, event handlers, event mediation settings | `Messaging.Abstractions` | none | | `LiteBus.Events` | Event mediator and event module | `Events.Abstractions`, `Messaging`, `Runtime.Abstractions` | none | | `LiteBus.Inbox.Abstractions` | Inbox scheduler contracts, envelopes, processor contracts, store roles | `Commands.Abstractions`, `Messaging.Abstractions` | none | | `LiteBus.Inbox` | Scheduler, inbox processor, inbox module | `Commands.Abstractions`, `Inbox.Abstractions`, `Messaging`, `Runtime.Abstractions` | none | | `LiteBus.Inbox.Extensions.Microsoft.Hosting` | Inbox processor background service, host options, health checks | `Inbox`, `Runtime.Extensions.Microsoft.DependencyInjection` | `Microsoft.Extensions.Hosting.Abstractions`, `Microsoft.Extensions.Diagnostics.HealthChecks` | | `LiteBus.Inbox.PostgreSql` | Raw Npgsql inbox store and schema helper | `Inbox.Abstractions`, `LiteBus.PostgreSql` | `Npgsql` | | `LiteBus.Inbox.PostgreSql.Extensions.Microsoft.Hosting` | Opt-in PostgreSQL inbox schema bootstrap hosted service | `Inbox.PostgreSql`, Microsoft DI runtime adapter | `Microsoft.Extensions.Hosting.Abstractions` | | `LiteBus.Outbox.Abstractions` | Outbox writer contracts, envelopes, processor contracts, dispatcher contract, store roles | `Messaging.Abstractions` | none | | `LiteBus.Outbox` | Outbox writer, integration outbox, outbox processor, LiteBus event dispatcher, outbox module | `Events.Abstractions`, `Messaging`, `Outbox.Abstractions`, `Runtime.Abstractions` | none | | `LiteBus.Outbox.Extensions.Microsoft.Hosting` | Outbox processor background service, host options, health checks | `Outbox`, `Runtime.Extensions.Microsoft.DependencyInjection` | `Microsoft.Extensions.Hosting.Abstractions`, `Microsoft.Extensions.Diagnostics.HealthChecks` | | `LiteBus.Outbox.PostgreSql` | Raw Npgsql outbox store and schema helper | `Outbox.Abstractions`, `LiteBus.PostgreSql` | `Npgsql` | | `LiteBus.Outbox.PostgreSql.Extensions.Microsoft.Hosting` | Opt-in PostgreSQL outbox schema bootstrap hosted service | `Outbox.PostgreSql`, Microsoft DI runtime adapter | `Microsoft.Extensions.Hosting.Abstractions` | | `LiteBus.PostgreSql` | Shared PostgreSQL identifier quoting, schema version metadata, advisory locks | none | `Npgsql` | | `LiteBus.*.Extensions.Microsoft.Hosting` | Processor host `IHostedService` wrappers and health checks | Module package, Microsoft DI runtime adapter | Microsoft hosting and health-check packages | | `LiteBus.*.Extensions.Microsoft.DependencyInjection` | Module registration adapters for Microsoft DI | Module package, Microsoft DI runtime adapter | Microsoft DI adapter dependency only | | `LiteBus.*.Extensions.Autofac` | Module registration adapters for Autofac | Module package, Autofac runtime adapter | Autofac adapter dependency only | | `LiteBus` | Aggregate package for core modules and storage modules | Commands, Queries, Events, Messaging, Inbox, Outbox, and abstractions | none beyond referenced packages | ## Test and Tooling Dependencies Test-only packages live under `tests/Directory.Packages.props`. | Package | Used for | | --- | --- | | `xunit`, `xunit.runner.visualstudio` | Unit and integration test execution | | `AwesomeAssertions` | Test assertions | | `Microsoft.NET.Test.Sdk` | .NET test host | | `coverlet.collector`, `coverlet.msbuild` | Coverage collection | | `Testcontainers.PostgreSql` | PostgreSQL integration tests | | `Npgsql` | PostgreSQL integration tests | The PostgreSQL integration tests require Docker because Testcontainers starts `postgres:16-alpine` during the test run. ## Module Setup Options ### Core Mediators ```csharp builder.Services.AddLiteBus(liteBus => { liteBus.AddCommandModule(commands => { commands.RegisterFromAssembly(typeof(Program).Assembly); }); liteBus.AddQueryModule(queries => { queries.RegisterFromAssembly(typeof(Program).Assembly); }); liteBus.AddEventModule(events => { events.RegisterFromAssembly(typeof(Program).Assembly); }); }); ``` ### Command Inbox ```csharp builder.Services.AddLiteBus(liteBus => { liteBus.AddCommandInboxModule(inbox => { inbox.Contracts.Register( "payments.commands.process-payment", version: 1); inbox.UseProcessorOptions(new CommandInboxProcessorOptions { BatchSize = 50, LeaseDuration = TimeSpan.FromMinutes(2) }); }); }); ``` The inbox module registers `ICommandScheduler` and `ICommandInboxProcessor`. A store module or application registration must provide `ICommandInboxWriter`, `ICommandInboxLeaseStore`, and `ICommandInboxStateStore`. ### Outbox ```csharp builder.Services.AddLiteBus(liteBus => { liteBus.AddOutboxModule(outbox => { outbox.Contracts.Register( "orders.events.order-submitted", version: 1); outbox.UseProcessorOptions(new OutboxProcessorOptions { BatchSize = 100, LeaseDuration = TimeSpan.FromMinutes(2) }); }); }); ``` The outbox module registers `IOutboxWriter`, `IIntegrationOutbox`, and `IOutboxProcessor`. It registers a dispatcher only when `UseLiteBusEventDispatcher()` is called. Broker dispatchers should register `IOutboxDispatcher` themselves. ### PostgreSQL Stores ```csharp var dataSource = NpgsqlDataSource.Create(connectionString); builder.Services.AddLiteBus(liteBus => { liteBus.AddPostgreSqlCommandInboxStore(postgres => { postgres.UseDataSource(dataSource); postgres.UseOptions(new PostgreSqlInboxStoreOptions { SchemaName = "app", TableName = "litebus_inbox_commands" }); }); liteBus.AddPostgreSqlOutboxStore(postgres => { postgres.UseDataSource(dataSource); postgres.UseOptions(new PostgreSqlOutboxStoreOptions { SchemaName = "app", TableName = "litebus_outbox_messages" }); }); }); ``` Call `PostgreSqlInboxSchema.EnsureAsync` / `PostgreSqlOutboxSchema.EnsureAsync`, copy `GetCreateScript` into your migration tool, or enable opt-in host bootstrap. See [PostgreSQL Schema Management](PostgreSQL-Schema-Management.md). ## Dependency Rules - Query packages do not depend on inbox or outbox packages. - PostgreSQL packages do not depend on EF Core. - Inbox and outbox abstractions do not depend on PostgreSQL, broker clients, or hosting packages. - The command inbox schedules future command execution. The outbox stores facts for later publication. - Stable contracts use names and versions. They do not store assembly-qualified type names. - Closed generic messages are supported when each closed type is registered. Open generic contracts are not supported.