Class CloudEventsServiceCollectionExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- Excalibur.Dispatch.dll
Extension methods for configuring CloudEvents support in Excalibur.Dispatch.
public static class CloudEventsServiceCollectionExtensions
- Inheritance
-
CloudEventsServiceCollectionExtensions
- Inherited Members
Methods
AddCloudEventOptionsValidation(IServiceCollection)
Registers the CloudEventOptions validator so a ValidateOnStart() call on the
CloudEvents options is not a no-op. Transport UseCloudEvents(services) entry points call this so
a misconfigured CloudEventOptions fails fast at startup on every transport — matching the
core AddCloudEvents path — rather than validating only when the core spine is also wired.
Idempotent (TryAddEnumerable): safe to call alongside AddCloudEvents.
public static IServiceCollection AddCloudEventOptionsValidation(this IServiceCollection services)
Parameters
servicesIServiceCollectionThe service collection.
Returns
- IServiceCollection
The service collection for chaining.
AddCloudEventSchemaAutoRegistration(IDispatchBuilder, Func<Type, string>, Func<Type, string>?)
Configures automatic schema registration for CloudEvents.
public static IDispatchBuilder AddCloudEventSchemaAutoRegistration(this IDispatchBuilder builder, Func<Type, string> schemaProvider, Func<Type, string>? versionProvider = null)
Parameters
Returns
AddCloudEventSchemaRegistry<TRegistry>(IDispatchBuilder)
Adds a schema registry for CloudEvent schema management.
public static IDispatchBuilder AddCloudEventSchemaRegistry<TRegistry>(this IDispatchBuilder builder) where TRegistry : class, ISchemaRegistry
Parameters
builderIDispatchBuilder
Returns
Type Parameters
TRegistry
AddCloudEventSerializerGuard(IServiceCollection)
Registers a fail-fast placeholder for CloudEventSerializer so a transport-only registration reports the missing configuration actionably instead of failing with a bare unresolved-service error.
public static IServiceCollection AddCloudEventSerializerGuard(this IServiceCollection services)
Parameters
servicesIServiceCollectionThe service collection.
Returns
- IServiceCollection
The service collection for chaining.
Remarks
Payload serialization is chosen once, by whichever AddCloudEvents overload the consumer
calls — a source-generated resolver or the annotated reflection path. A transport's
UseCloudEvents cannot make that choice on the consumer's behalf without either guessing or
dragging a trimming annotation onto every transport entry point, so it registers this guard
instead.
Registered with TryAdd, so a real serializer registered by AddCloudEvents — in
either order — always wins, and the factory below is never invoked. It throws only when nothing
configured CloudEvents serialization at all and something then tries to use it.
Exceptions
- ArgumentNullException
Thrown when
servicesis null.
AddCloudEvents(IDispatchBuilder, Action<CloudEventOptions>?)
Adds the core CloudEvents spine to the dispatcher: the envelope⇄CloudEvent bridge, the envelope
converter, and validated CloudEventOptions. This is the single canonical entry point —
a core-only application (no transport package) gets a working IEnvelopeCloudEventBridge,
and each transport's UseCloudEvents(services) composes on top of it idempotently (all
registrations use TryAdd). This method registers services only; it does not add the ingress
middleware. To enable the ingress middleware, call builder.UseCloudEvents() explicitly on the
dispatch pipeline.
[RequiresUnreferencedCode("CloudEvents payloads are serialized reflectively on this path. Call the overload taking an IJsonTypeInfoResolver with a source-generated context covering the types you publish as CloudEvent data.")]
[RequiresDynamicCode("CloudEvents payloads are serialized reflectively on this path. Call the overload taking an IJsonTypeInfoResolver with a source-generated context covering the types you publish as CloudEvent data.")]
public static IDispatchBuilder AddCloudEvents(this IDispatchBuilder builder, Action<CloudEventOptions>? configure = null)
Parameters
builderIDispatchBuilderThe dispatch builder.
configureAction<CloudEventOptions>Optional action to configure CloudEventOptions.
Returns
- IDispatchBuilder
The dispatch builder for chaining.
Remarks
This overload serializes payloads reflectively and is annotated accordingly. Prefer AddCloudEvents(IDispatchBuilder, IJsonTypeInfoResolver, Action<CloudEventOptions>?), which takes a source-generated resolver and carries no annotation.
The annotation is deliberate and is the point of the split. A single entry point that chose reflection when no resolver happened to be configured would make the consumer who opted into reflection indistinguishable from the consumer who did not — so neither would be warned, and a trimmed or ahead-of-time publish would fail on the consumer's machine instead of at their build.
AddCloudEvents(IDispatchBuilder, IJsonTypeInfoResolver, Action<CloudEventOptions>?)
Adds the core CloudEvents spine with reflection-free payload serialization, using the consumer's source-generated resolver. This is the overload to use when the host is trimmed or published ahead-of-time.
public static IDispatchBuilder AddCloudEvents(this IDispatchBuilder builder, IJsonTypeInfoResolver payloadTypeInfoResolver, Action<CloudEventOptions>? configure = null)
Parameters
builderIDispatchBuilderThe dispatch builder.
payloadTypeInfoResolverIJsonTypeInfoResolverA source-generated resolver covering the types published as CloudEvent data — typically a JsonSerializerContext declared by the consumer.
configureAction<CloudEventOptions>Optional action to configure CloudEventOptions.
Returns
- IDispatchBuilder
The dispatch builder for chaining.
Exceptions
- ArgumentNullException
Thrown when a required argument is null.
AddInMemorySchemaRegistry(IDispatchBuilder)
Adds an in-memory schema registry for development/testing.
public static IDispatchBuilder AddInMemorySchemaRegistry(this IDispatchBuilder builder)
Parameters
builderIDispatchBuilder
Returns
WithCloudEventExtensions(IDispatchBuilder, Action<HashSet<string>>)
Configures CloudEvent extension attributes to include/exclude.
public static IDispatchBuilder WithCloudEventExtensions(this IDispatchBuilder builder, Action<HashSet<string>> configureExclusions)
Parameters
builderIDispatchBuilderconfigureExclusionsAction<HashSet<string>>