Skip to main content

Hosting Providers

Dispatch provides dedicated hosting packages for each deployment model. Each package handles framework-specific lifecycle, DI integration, and cold-start optimization.

Before You Start

  • .NET 8.0+ (or .NET 9/10 for latest features)
  • Familiarity with dependency injection and your target hosting model

Hosting Packages

PackageTargetUse Case
Excalibur.Dispatch.Hosting.AspNetCoreASP.NET CoreWeb APIs, background services, long-running hosts
Excalibur.Dispatch.Hosting.AwsLambdaAWS LambdaEvent-driven serverless on AWS
Excalibur.Dispatch.Hosting.AzureFunctionsAzure FunctionsEvent-driven serverless on Azure
Excalibur.Dispatch.Hosting.GoogleCloudFunctionsGoogle Cloud FunctionsEvent-driven serverless on GCP
Excalibur.Dispatch.Hosting.LambdaGeneric LambdaShared Lambda abstractions
Excalibur.Dispatch.Hosting.Serverless.AbstractionsAll serverlessShared serverless base types

ASP.NET Core

The primary hosting model for web APIs and long-running services.

Installation

dotnet add package Excalibur.Dispatch.Hosting.AspNetCore

Setup

var builder = WebApplication.CreateBuilder(args);

// Register Dispatch with ASP.NET Core integration
builder.AddDispatch(configure: dispatch =>
{
dispatch.AddHandlersFromAssembly(typeof(Program).Assembly);
});

var app = builder.Build();
app.Run();

The AddDispatch() extension on WebApplicationBuilder integrates Dispatch with the ASP.NET Core host, registering middleware, health checks, and background services.

Features

  • Full middleware pipeline integration
  • Background service hosting for outbox processors, leader election
  • Health check registration
  • OpenTelemetry tracing integration
  • Request-scoped dispatcher via dependency injection

AWS Lambda

Event-driven serverless hosting for AWS workloads.

Installation

dotnet add package Excalibur.Dispatch.Hosting.AwsLambda

Setup

using Microsoft.Extensions.DependencyInjection;

// In your Lambda startup
services.AddAwsLambdaServerless();

// Or with configuration
services.AddAwsLambdaServerless(options =>
{
// Configure serverless-specific options
});

Cold Start Optimization

Lambda cold starts require careful initialization:

  • Minimize DI registrations — Only register what the function needs
  • Use static initialization — Pre-warm the DI container outside the handler
  • Avoid leader election — Not applicable in serverless (no persistent instances)
  • Use manual outbox processingIOutboxProcessor for on-demand trigger instead of background services

Example Handler

public class OrderFunction
{
private readonly IDispatcher _dispatcher;

public OrderFunction(IDispatcher dispatcher)
{
_dispatcher = dispatcher;
}

public async Task<APIGatewayProxyResponse> HandleAsync(
APIGatewayProxyRequest request,
ILambdaContext context)
{
var command = JsonSerializer.Deserialize<CreateOrderCommand>(request.Body);
var result = await _dispatcher.DispatchAsync(command!, CancellationToken.None);
return new APIGatewayProxyResponse { StatusCode = 200 };
}
}

For a detailed deployment guide, see AWS Lambda Deployment.


Azure Functions

Event-driven serverless hosting for Azure workloads.

Installation

dotnet add package Excalibur.Dispatch.Hosting.AzureFunctions

Setup

using Microsoft.Extensions.DependencyInjection;

// In your Functions startup
services.AddAzureFunctionsServerless();

// Or with configuration
services.AddAzureFunctionsServerless(options =>
{
// Configure serverless-specific options
});

Example Function

public class OrderFunction
{
private readonly IDispatcher _dispatcher;

public OrderFunction(IDispatcher dispatcher)
{
_dispatcher = dispatcher;
}

[Function("CreateOrder")]
public async Task<HttpResponseData> Run(
[HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req)
{
var command = await req.ReadFromJsonAsync<CreateOrderCommand>();
await _dispatcher.DispatchAsync(command!, CancellationToken.None);

var response = req.CreateResponse(HttpStatusCode.OK);
return response;
}
}

Lifecycle Considerations

  • Azure Functions uses IHost — Dispatch integrates via standard DI
  • Durable Functions can coordinate long-running workflows alongside Dispatch sagas
  • Use IOutboxProcessor for manual trigger in consumption plan (no background services)

For a detailed deployment guide, see Azure Functions Deployment.


Google Cloud Functions

Event-driven serverless hosting for Google Cloud workloads.

Installation

dotnet add package Excalibur.Dispatch.Hosting.GoogleCloudFunctions

Setup

using Microsoft.Extensions.DependencyInjection;

// In your Cloud Functions startup
services.AddGoogleCloudFunctionsServerless();

// Or with configuration
services.AddGoogleCloudFunctionsServerless(options =>
{
// Configure serverless-specific options
});

Example Function

public class OrderFunction : IHttpFunction
{
private readonly IDispatcher _dispatcher;

public OrderFunction(IDispatcher dispatcher)
{
_dispatcher = dispatcher;
}

public async Task HandleAsync(HttpContext context)
{
var command = await context.Request.ReadFromJsonAsync<CreateOrderCommand>();
await _dispatcher.DispatchAsync(command!, context.RequestAborted);
context.Response.StatusCode = 200;
}
}

For a detailed deployment guide, see Google Cloud Functions Deployment.


Serverless Considerations

All serverless hosting models share common constraints:

ConcernRecommendation
Background servicesNot available — use IOutboxProcessor for on-demand processing
Leader electionNot applicable — no persistent instances
Long-running sagasUse external orchestration (Step Functions, Durable Functions)
Cold startsMinimize DI graph, use static initialization
Connection poolingUse connection string pooling, avoid IUnitOfWork across requests
IdempotencyCritical — serverless may retry invocations

Integration with Leader Election

Leader election is designed for multi-instance deployments (Kubernetes, App Service), not serverless:

// ASP.NET Core — use leader election for background processing
services.AddExcaliburLeaderElection();

// Serverless — use manual outbox processing instead
// The function invocation IS the processing trigger

See Also