# Class Extensions OptimaJet.Workflow.Api.Extensions This class contains extensions for configuring Workflow Engine Api services and connecting ASP.NET middleware. Namespace: [OptimaJet.Workflow.Api](https://api.workflowengine.io/web-api/OptimaJet.Workflow.Api/) ```csharp public static class Extensions ``` ## Methods `public static IServiceCollection ConfigureWorkflowApi(this IServiceCollection services, Action configure)` Registers operation configuration to run once after all module defaults are loaded. ### Parameters | Name | Type | Description | | --- | --- | --- | | `services` | `IServiceCollection` | The application's services. | | `configure` | `Action` | An action that selects operations and registers callbacks. | ### Returns | Type | Description | | --- | --- | | `IServiceCollection` | The same service collection. | ### Remarks Actions run in registration order and may be registered before or after Core and Forms. This method does not register Core, runtimes or security. Resolve request-scoped dependencies inside callbacks through [IOperationContext.Services](https://api.workflowengine.io/web-api/OptimaJet.Workflow.Api.Configuration/IOperationContext/). `public static IServiceCollection AddWorkflowApiCore(this IServiceCollection services, Action? setupAction = null)` Adds the core Workflow Engine Web Api services, enabling you to add endpoints using [Extensions.MapWorkflowApi(IEndpointRouteBuilder)](https://api.workflowengine.io/web-api/OptimaJet.Workflow.Api/Extensions/). ### Parameters | Name | Type | Description | | --- | --- | --- | | `services` | `IServiceCollection` | The [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection). | | `setupAction` | `Action` | A delegate to configure the core Workflow Engine Api options. | ### Returns | Type | Description | | --- | --- | | `IServiceCollection` | A [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection) that can be used to further configure services. | `public static IServiceCollection AddWorkflowRuntime(this IServiceCollection services, Action? setupAction = null)` Creates WorkflowRuntime and registers it with the service collection in single-tenant mode. For multi-tenant applications, use [Extensions.AddWorkflowTenants(IServiceCollection, params WorkflowTenantCreationOptions\[\])](https://api.workflowengine.io/web-api/OptimaJet.Workflow.Api/Extensions/) instead. ### Parameters | Name | Type | Description | | --- | --- | --- | | `services` | `IServiceCollection` | The [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection). | | `setupAction` | `Action` | A delegate to configure the Workflow Runtime options. Using this method implies single-tenant mode, so the tenant ids will be set to a [WorkflowApiConstants.SingleTenantId](https://api.workflowengine.io/web-api/OptimaJet.Workflow.Api/WorkflowApiConstants/). | ### Returns | Type | Description | | --- | --- | | `IServiceCollection` | A [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection) that can be used to further configure services. | `public static IServiceCollection AddWorkflowTenants(this IServiceCollection services, params WorkflowTenantCreationOptions[] options)` Creates [IWorkflowTenant](https://api.workflowengine.io/web-api/OptimaJet.Workflow.Api/IWorkflowTenant/) implementations and registers them with the service collection in multi-tenant mode. For single-tenant applications, use [Extensions.AddWorkflowRuntime(IServiceCollection, Action?)](https://api.workflowengine.io/web-api/OptimaJet.Workflow.Api/Extensions/) instead. ### Parameters | Name | Type | Description | | --- | --- | --- | | `services` | `IServiceCollection` | The [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection). | | `options` | `WorkflowTenantCreationOptions[]` | An array of options for creating the tenants. | ### Returns | Type | Description | | --- | --- | | `IServiceCollection` | A [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection) that can be used to further configure services. | `public static IServiceCollection AddWorkflowTenants(this IServiceCollection services, IEnumerable options)` Creates [IWorkflowTenant](https://api.workflowengine.io/web-api/OptimaJet.Workflow.Api/IWorkflowTenant/) implementations and registers them with the service collection in multi-tenant mode. For single-tenant applications, use [Extensions.AddWorkflowRuntime(IServiceCollection, Action?)](https://api.workflowengine.io/web-api/OptimaJet.Workflow.Api/Extensions/) instead. ### Parameters | Name | Type | Description | | --- | --- | --- | | `services` | `IServiceCollection` | The [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection). | | `options` | `IEnumerable` | An enumerable of options for creating the tenants. | ### Returns | Type | Description | | --- | --- | | `IServiceCollection` | A [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection) that can be used to further configure services. | `public static IServiceCollection AddWorkflowApiSecurity(this IServiceCollection services, Action? setupAction = null)` Adds services to provide authentication and authorization to Workflow Engine Web Api endpoints. ### Parameters | Name | Type | Description | | --- | --- | --- | | `services` | `IServiceCollection` | The [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection). | | `setupAction` | `Action` | A delegate to configure the security options for Workflow Engine Api. | ### Returns | Type | Description | | --- | --- | | `IServiceCollection` | A [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection) that can be used to further configure services. | `public static IEndpointRouteBuilder MapWorkflowApi(this IEndpointRouteBuilder endpoints)` Maps all Workflow Engine Web Api endpoints to the specified [IEndpointRouteBuilder](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.routing.iendpointroutebuilder). When using this method, you must first add services using [Extensions.AddWorkflowApiCore(IServiceCollection, Action?)](https://api.workflowengine.io/web-api/OptimaJet.Workflow.Api/Extensions/). ### Parameters | Name | Type | Description | | --- | --- | --- | | `endpoints` | `IEndpointRouteBuilder` | The [IEndpointRouteBuilder](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.routing.iendpointroutebuilder). | ### Returns | Type | Description | | --- | --- | | `IEndpointRouteBuilder` | A [IEndpointRouteBuilder](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.routing.iendpointroutebuilder) that can be used to further configure endpoints. | `public static IWorkflowTenantSnapshot GetHttpContextWorkflowTenantSnapshot(this IServiceProvider services)` Gets the workflow tenant snapshot from the current HTTP context. ### Parameters | Name | Type | Description | | --- | --- | --- | | `services` | `IServiceProvider` | | ### Returns | Type | Description | | --- | --- | | `IWorkflowTenantSnapshot` | The workflow tenant snapshot. | `public static string GetHttpContextWorkflowTenantId(this IServiceProvider services)` Gets the workflow tenant id from the current HTTP context based on the provided header or default tenant id. ### Parameters | Name | Type | Description | | --- | --- | --- | | `services` | `IServiceProvider` | The [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection). | ### Returns | Type | Description | | --- | --- | | `String` | The tenant id. | `public static IWorkflowTenant GetHttpContextWorkflowTenant(this IServiceProvider services)` Gets the workflow tenant instance from the current HTTP context. ### Parameters | Name | Type | Description | | --- | --- | --- | | `services` | `IServiceProvider` | The [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection). | ### Returns | Type | Description | | --- | --- | | `IWorkflowTenant` | \>The tenant instance. | `public static WorkflowRuntime GetHttpContextWorkflowRuntime(this IServiceProvider services)` Gets the workflow runtime instance for the workflow tenant identified in the current HTTP context. ### Parameters | Name | Type | Description | | --- | --- | --- | | `services` | `IServiceProvider` | The [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection). | ### Returns | Type | Description | | --- | --- | | `WorkflowRuntime` | \>The workflow runtime instance. | [Next IDataProvider](https://api.workflowengine.io/web-api/OptimaJet.Workflow.Api/IDataProvider/)