Skip to content

Generated Code

The Integration Events generator produces everything the Event Queue generator does — ChannelWorker<T>, EventQueueChannel<T>, effect methods, DI registration — plus additional infrastructure for cross-service scenarios.

Event Type Registry

The generator produces a static EventTypeRegistry dictionary on the publisher class, mapping stable wire names (from [IntegrationEvent]) to CLR types:

// Generated on OrderingIntegrationEvents
public static readonly Dictionary<string, Type> EventTypeRegistry = new()
{
    ["ordering.order-placed"] = typeof(OrderingEvents.OrderPlaced),
    ["ordering.order-cancelled"] = typeof(OrderingEvents.OrderCancelled),
};

The registry is keyed by wire name — the value from each event type's [IntegrationEvent("...")] attribute. External transports use this registry for polymorphic deserialization — given a wire name in an incoming message, the transport looks up the corresponding CLR type and deserializes accordingly.

Wire Name Manifest

The deepstaging sync command (run automatically after build) queries the projection layer to discover all [IntegrationEvent] wire names and writes wire-manifest.json. This is the same projection API the generator uses for EventTypeRegistry — the CLI just queries it directly via MSBuildWorkspace.

See Wire Name Manifest for the full workflow including retirement and DSEQ08/DSEQ11 diagnostics.

Transport Injection via SetTransport

The generated publisher class exposes a SetTransport() method for replacing the default in-process channel with an external transport:

// Generated on OrderingIntegrationEvents
public static void SetTransport(IEventTransport<object> transport)
{
    _channel!.SetTransport(transport);
}

This is typically called during runtime bootstrap configuration:

builder.AddOrderingRuntime(rt =>
{
    rt.PublishToServiceBus<OrderingEvents>();      // sets transport on publisher
    rt.SubscribeFromServiceBus<BasketEvents>();    // sets transport on subscriber
});

Azure Service Bus

The PublishToServiceBus<T>() and SubscribeFromServiceBus<T>() methods are generated by the Deepstaging.Cloud.Azure package when Azure Service Bus is configured. They wire up ServiceBusEventTransport<object> with the EventTypeRegistry automatically.

Bootstrap Methods

The generator produces two registration methods:

// Full DI registration (production)
public static IServiceCollection AddOrderingIntegrationEventsServices(
    this IServiceCollection services) { ... }

// Channel-only initialization (testing)
public static void InitializeChannel() { ... }

For handlers (subscribers), the bootstrap additionally registers a BackgroundService worker that consumes events from the channel:

// Generated on the handler class
public static IServiceCollection AddOrderingCatalogEventHandlersServices(
    this IServiceCollection services)
{
    var channel = new EventQueueChannel<object>(10000, true, false);
    Initialize(channel);
    services.AddHostedService(sp =>
        new OrderingCatalogEventHandlersWorker(channel, ...));
    return services;
}

Test environments

Use InitializeChannel() (no worker, no transport) for test scenarios where events are verified via DrainAll() instead of dispatched by the worker.

Shared Runtime Infrastructure

Integration Events reuses the same runtime types as Event Queue. See the Event Queue Generated Code reference for details on: