Class SagaServiceCollectionExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- Stratara.Sagas.dll
Service-collection extensions for the Stratara saga runtime.
public static class SagaServiceCollectionExtensions
- Inheritance
-
SagaServiceCollectionExtensions
- Inherited Members
Methods
AddSagaHandling(IServiceCollection, IConfiguration)
Registers the saga runtime services (ISagaManager, ISagaHandler,
ISagaMethodInvoker) without the hosted SagaWorker, and binds SagaOptions from
the Sagas configuration section. For a host whose sagas are fed by something other than the bus,
such as the Orleans execution model's store readers. Calling it more than once registers each service once.
public static IServiceCollection AddSagaHandling(this IServiceCollection services, IConfiguration configuration)
Parameters
servicesIServiceCollectionThe service collection.
configurationIConfigurationThe configuration root used to bind
SagaOptions.
Returns
- IServiceCollection
The same service collection for chaining.
Examples
services.AddSagasFromAssemblyContaining<TransferSaga>();
services.AddSagaHandling(configuration);
AddSagaWorker(IServiceCollection, IConfiguration)
Registers the saga runtime services (ISagaManager, ISagaHandler,
ISagaMethodInvoker) and the hosted SagaWorker; binds SagaOptions from
the Sagas configuration section.
public static IServiceCollection AddSagaWorker(this IServiceCollection services, IConfiguration configuration)
Parameters
servicesIServiceCollectionconfigurationIConfiguration
Returns
Examples
Binds SagaOptions from the Sagas section and consumes the event-bundle saga
subscription. Register the sagas separately:
services.AddSagasFromAssemblyContaining<TransferSaga>();
services.AddSagaWorker(configuration);
Remarks
Use together with AddSagasFromAssemblyContaining<T>(IServiceCollection) to discover concrete saga implementations.
AddSagasFromAssemblyContaining<T>(IServiceCollection)
Scans the assembly that contains T for concrete ISaga
implementations and registers each as a scoped ISaga.
public static IServiceCollection AddSagasFromAssemblyContaining<T>(this IServiceCollection services)
Parameters
servicesIServiceCollection
Returns
Type Parameters
TAny type from the assembly to scan.
Examples
Discover and register every ISaga in the saga assembly:
public interface ISagasMarker { }
builder.Services.AddSagasFromAssemblyContaining<ISagasMarker>();
Exceptions
- InvalidOperationException
The host was already built from
services, which is read-only: the types the running host trusts would change under it.