Extension Methods
This page provides detailed reference documentation for all AsyncEndpoints extension methods, including their signatures, parameters, return types, and usage examples.
AddAsyncEndpoints
Signature
public static IServiceCollection AddAsyncEndpoints(
this IServiceCollection services,
Action<AsyncEndpointsConfigurations>? configureOptions = null)
Parameters
- services (
IServiceCollection): TheIServiceCollectionto add services to - configureOptions (
Action<AsyncEndpointsConfigurations>): Optional action to configure AsyncEndpoints options
Returns
- IServiceCollection: The
IServiceCollectionfor method chaining
Description
Adds the core AsyncEndpoints services to the dependency injection container.
Example
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAsyncEndpoints(options =>
{
options.WorkerConfigurations.MaximumConcurrency = Environment.ProcessorCount;
options.JobManagerConfiguration.DefaultMaxRetries = 3;
});
AddAsyncEndpointsInMemoryStore
Signature
public static IServiceCollection AddAsyncEndpointsInMemoryStore(
this IServiceCollection services)
Parameters
- services (
IServiceCollection): TheIServiceCollectionto add services to
Returns
- IServiceCollection: The
IServiceCollectionfor method chaining
Description
Adds an in-memory job store implementation to the dependency injection container. Use this for development or single-instance deployments.
Example
builder.Services
.AddAsyncEndpoints()
.AddAsyncEndpointsInMemoryStore();
AddAsyncEndpointsRedisStore (Connection String)
Signature
public static IServiceCollection AddAsyncEndpointsRedisStore(
this IServiceCollection services,
string connectionString)
Parameters
- services (
IServiceCollection): TheIServiceCollectionto add services to - connectionString (
string): The Redis connection string
Returns
- IServiceCollection: The
IServiceCollectionfor method chaining
Description
Adds a Redis-based job store implementation using a connection string.
Example
builder.Services
.AddAsyncEndpoints()
.AddAsyncEndpointsRedisStore("localhost:6379");
AddAsyncEndpointsRedisStore (Connection Multiplexer)
Signature
public static IServiceCollection AddAsyncEndpointsRedisStore(
this IServiceCollection services,
IConnectionMultiplexer connectionMultiplexer)
Parameters
- services (
IServiceCollection): TheIServiceCollectionto add services to - connectionMultiplexer (
IConnectionMultiplexer): The Redis connection multiplexer instance
Returns
- IServiceCollection: The
IServiceCollectionfor method chaining
Description
Adds a Redis-based job store implementation using a pre-configured connection multiplexer.
Example
var connection = ConnectionMultiplexer.Connect("localhost:6379");
builder.Services
.AddAsyncEndpoints()
.AddAsyncEndpointsRedisStore(connection);
AddAsyncEndpointsRedisStore (Configuration Action)
Signature
public static IServiceCollection AddAsyncEndpointsRedisStore(
this IServiceCollection services,
Action<RedisConfiguration> setupAction)
Parameters
- services (
IServiceCollection): TheIServiceCollectionto add services to - setupAction (
Action<RedisConfiguration>): Action to configure the Redis connection
Returns
- IServiceCollection: The
IServiceCollectionfor method chaining
Description
Adds a Redis-based job store implementation with configuration action.
Example
builder.Services
.AddAsyncEndpoints()
.AddAsyncEndpointsRedisStore(config =>
{
config.ConnectionString = "localhost:6379";
config.Password = "your-password";
});
AddAsyncEndpointsWorker
Signature
public static IServiceCollection AddAsyncEndpointsWorker(
this IServiceCollection services,
Action<AsyncEndpointsRecoveryConfiguration>? recoveryConfiguration = null)
Parameters
- services (
IServiceCollection): TheIServiceCollectionto add services to - recoveryConfiguration (
Action<AsyncEndpointsRecoveryConfiguration>): Optional configuration for distributed job recovery
Returns
- IServiceCollection: The
IServiceCollectionfor method chaining
Description
Adds the background worker services required to process async jobs.
Example
builder.Services
.AddAsyncEndpoints()
.AddAsyncEndpointsRedisStore("localhost:6379")
.AddAsyncEndpointsWorker(recoveryConfiguration =>
{
recoveryConfiguration.EnableDistributedJobRecovery = true;
recoveryConfiguration.JobTimeoutMinutes = 30;
});
AddAsyncEndpointHandler (With Request and Response)
Signature
public static IServiceCollection AddAsyncEndpointHandler<
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
TAsyncEndpointRequestHandler,
TRequest,
TResponse>(
this IServiceCollection services,
string jobName)
where TAsyncEndpointRequestHandler : class, IAsyncEndpointRequestHandler<TRequest, TResponse>
Parameters
- services (
IServiceCollection): TheIServiceCollectionto add services to - jobName (
string): The unique name of the job, used to identify the specific handler
Type Parameters
- TAsyncEndpointRequestHandler: The type of the handler that implements
IAsyncEndpointRequestHandler<TRequest, TResponse> - TRequest: The type of the request object
- TResponse: The type of the response object
Returns
- IServiceCollection: The
IServiceCollectionfor method chaining
Description
Registers an asynchronous endpoint handler for processing requests of type TRequest and returning responses of type TResponse.
Example
builder.Services.AddAsyncEndpointHandler<ProcessDataHandler, DataRequest, ProcessResult>("ProcessData");
AddAsyncEndpointHandler (No-Body Request)
Signature
public static IServiceCollection AddAsyncEndpointHandler<
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
TAsyncEndpointRequestHandler,
TResponse>(
this IServiceCollection services,
string jobName)
where TAsyncEndpointRequestHandler : class, IAsyncEndpointRequestHandler<TResponse>
Parameters
- services (
IServiceCollection): TheIServiceCollectionto add services to - jobName (
string): A unique name for the async job, used for identifying the handler
Type Parameters
- TAsyncEndpointRequestHandler: The type of the handler that implements
IAsyncEndpointRequestHandler<TResponse> - TResponse: The type of the response object
Returns
- IServiceCollection: The
IServiceCollectionfor method chaining
Description
Adds an asynchronous endpoint handler for requests without body to the service collection.
Example
builder.Services.AddAsyncEndpointHandler<GenerateReportHandler, ReportResult>("GenerateReport");
MapAsyncPost (With Request Body)
Signature
public static IEndpointConventionBuilder MapAsyncPost<TRequest>(
this IEndpointRouteBuilder endpoints,
string jobName,
string pattern,
Func<HttpContext, TRequest, CancellationToken, Task<IResult?>?>? handler = null)
Parameters
- endpoints (
IEndpointRouteBuilder): TheIEndpointRouteBuilderto add the route to - jobName (
string): A unique name for the async job, used for identifying the handler - pattern (
string): The URL pattern for the endpoint - handler (
Func<HttpContext, TRequest, CancellationToken, Task<IResult?>?>): Optional custom handler function
Type Parameters
- TRequest: The type of the request object
Returns
- IEndpointConventionBuilder: That can be used to further configure the endpoint
Description
Maps an asynchronous POST endpoint that processes requests in the background with a request body.
Example
app.MapAsyncPost<DataRequest>("ProcessData", "/api/process-data");
MapAsyncPost (No-Body Request)
Signature
public static IEndpointConventionBuilder MapAsyncPost(
this IEndpointRouteBuilder endpoints,
string jobName,
string pattern,
Func<HttpContext, NoBodyRequest, CancellationToken, Task<IResult?>?>? handler = null)
Parameters
- endpoints (
IEndpointRouteBuilder): TheIEndpointRouteBuilderto add the route to - jobName (
string): A unique name for the async job, used for identifying the handler - pattern (
string): The URL pattern for the endpoint - handler (
Func<HttpContext, NoBodyRequest, CancellationToken, Task<IResult?>?>): Optional custom handler function
Returns
- IEndpointConventionBuilder: That can be used to further configure the endpoint
Description
Maps an asynchronous POST endpoint that processes requests without body in the background.
Example
app.MapAsyncPost("GenerateReport", "/api/generate-report");
MapAsyncPut
Signature
public static IEndpointConventionBuilder MapAsyncPut<TRequest>(
this IEndpointRouteBuilder endpoints,
string jobName,
string pattern,
Func<HttpContext, TRequest, CancellationToken, Task<IResult?>?>? handler = null)
Parameters
- endpoints (
IEndpointRouteBuilder): TheIEndpointRouteBuilderto add the route to - jobName (
string): A unique name for the async job, used for identifying the handler - pattern (
string): The URL pattern for the endpoint - handler (
Func<HttpContext, TRequest, CancellationToken, Task<IResult?>?>): Optional custom handler function
Type Parameters
- TRequest: The type of the request object
Returns
- IEndpointConventionBuilder: That can be used to further configure the endpoint
Description
Maps an asynchronous PUT endpoint that processes requests in the background.
Example
app.MapAsyncPut<UpdateRequest>("UpdateData", "/api/update-data");
MapAsyncPatch
Signature
public static IEndpointConventionBuilder MapAsyncPatch<TRequest>(
this IEndpointRouteBuilder endpoints,
string jobName,
string pattern,
Func<HttpContext, TRequest, CancellationToken, Task<IResult?>?>? handler = null)
Parameters
- endpoints (
IEndpointRouteBuilder): TheIEndpointRouteBuilderto add the route to - jobName (
string): A unique name for the async job, used for identifying the handler - pattern (
string): The URL pattern for the endpoint - handler (
Func<HttpContext, TRequest, CancellationToken, Task<IResult?>?>): Optional custom handler function
Type Parameters
- TRequest: The type of the request object
Returns
- IEndpointConventionBuilder: That can be used to further configure the endpoint
Description
Maps an asynchronous PATCH endpoint that processes requests in the background.
Example
app.MapAsyncPatch<PartialUpdateRequest>("UpdatePartial", "/api/update-partial");
MapAsyncDelete
Signature
public static IEndpointConventionBuilder MapAsyncDelete<TRequest>(
this IEndpointRouteBuilder endpoints,
string jobName,
string pattern,
Func<HttpContext, TRequest, CancellationToken, Task<IResult?>?>? handler = null)
Parameters
- endpoints (
IEndpointRouteBuilder): TheIEndpointRouteBuilderto add the route to - jobName (
string): A unique name for the async job, used for identifying the handler - pattern (
string): The URL pattern for the endpoint - handler (
Func<HttpContext, TRequest, CancellationToken, Task<IResult?>?>): Optional custom handler function
Type Parameters
- TRequest: The type of the request object
Returns
- IEndpointConventionBuilder: That can be used to further configure the endpoint
Description
Maps an asynchronous DELETE endpoint that processes requests in the background.
Example
app.MapAsyncDelete<DeleteRequest>("DeleteData", "/api/delete-data");
MapAsyncGetJobDetails
Signature
public static IEndpointConventionBuilder MapAsyncGetJobDetails(
this IEndpointRouteBuilder endpoints,
string pattern = \"/jobs/{jobId:guid}\")
Parameters
- endpoints (
IEndpointRouteBuilder): TheIEndpointRouteBuilderto add the route to - pattern (
string): The URL pattern for the endpoint. Should contain a {jobId} parameter
Returns
- IEndpointConventionBuilder: That can be used to further configure the endpoint
Description
Maps an asynchronous GET endpoint that fetches job responses by job ID.
Example
app.MapAsyncGetJobDetails("/jobs/{jobId:guid}");