/// <summary> /// Executes the <paramref name="correlatedTask"/> with its own <see cref="CorrelationContext"/>. /// </summary> /// <typeparam name="T">The return type of the awaitable task.</typeparam> /// <param name="asyncCorrelationManager">The async correlation manager.</param> /// <param name="correlatedTask">The task to execute.</param> /// <param name="onException">A delegate to handle the exception inside the correlation scope, before it is disposed. Returns <see langword="true" /> to consider the exception handled, or <see langword="false" /> to throw.</param> /// <returns>An awaitable that completes with a result <typeparamref name="T"/> once the <paramref name="correlatedTask"/> has executed and the correlation context has disposed.</returns> /// <remarks> /// When logging and tracing are both disabled, no correlation context is created and the task simply executed as it normally would. /// </remarks> public static Task <T> CorrelateAsync <T>(this IAsyncCorrelationManager asyncCorrelationManager, Func <Task <T> > correlatedTask, OnException <T>?onException) { if (asyncCorrelationManager is null) { throw new ArgumentNullException(nameof(asyncCorrelationManager)); } return(asyncCorrelationManager.CorrelateAsync(null, correlatedTask, onException)); }
/// <summary> /// Executes the <paramref name="correlatedTask"/> with its own <see cref="CorrelationContext"/>. /// </summary> /// <param name="asyncCorrelationManager">The async correlation manager.</param> /// <param name="correlationId">The correlation id to use, or null to generate a new one.</param> /// <param name="correlatedTask">The task to execute.</param> /// <returns>An awaitable that completes once the <paramref name="correlatedTask"/> has executed and the correlation context has disposed.</returns> /// <remarks> /// When logging and tracing are both disabled, no correlation context is created and the task simply executed as it normally would. /// </remarks> public static Task CorrelateAsync(this IAsyncCorrelationManager asyncCorrelationManager, string?correlationId, Func <Task> correlatedTask) { if (asyncCorrelationManager is null) { throw new ArgumentNullException(nameof(asyncCorrelationManager)); } return(asyncCorrelationManager.CorrelateAsync(correlationId, correlatedTask, null)); }
public void When_creating_instance_without_asyncCorrelationManager_it_should_throw() { IAsyncCorrelationManager asyncCorrelationManager = null; // ReSharper disable once AssignNullToNotNullAttribute // ReSharper disable once ObjectCreationAsStatement Action act = () => new CorrelateIncomingMessageStep(asyncCorrelationManager, new NullLoggerFactory()); // Assert act.Should() .Throw <ArgumentNullException>() .Where(exception => exception.ParamName == nameof(asyncCorrelationManager)); }
/// <summary> /// Initializes a new instance of the <see cref="CorrelateMiddleware"/> class. /// </summary> /// <param name="next">The next request delegate to invoke in the request execution pipeline.</param> /// <param name="options">The options.</param> /// <param name="logger">The logger.</param> /// <param name="correlationContextAccessor">The correlation context accessor.</param> /// <param name="asyncCorrelationManager">The correlation manager.</param> public CorrelateMiddleware( RequestDelegate next, IOptions <CorrelateOptions> options, ILogger <CorrelateMiddleware> logger, ICorrelationContextAccessor correlationContextAccessor, IAsyncCorrelationManager asyncCorrelationManager) { _next = next ?? throw new ArgumentNullException(nameof(next)); _options = options?.Value ?? throw new ArgumentNullException(nameof(options)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _correlationContextAccessor = correlationContextAccessor ?? throw new ArgumentNullException(nameof(correlationContextAccessor)); _asyncCorrelationManager = asyncCorrelationManager ?? throw new ArgumentNullException(nameof(asyncCorrelationManager)); if (_options.RequestHeaders == null || !_options.RequestHeaders.Any()) { _acceptedRequestHeaders = ImmutableArray <string> .Empty; } else { _acceptedRequestHeaders = _options.RequestHeaders.ToImmutableArray(); } }
public CorrelateIncomingMessageStep(IAsyncCorrelationManager asyncCorrelationManager, IRebusLoggerFactory?rebusLoggerFactory) { _asyncCorrelationManager = asyncCorrelationManager ?? throw new ArgumentNullException(nameof(asyncCorrelationManager)); _logger = (rebusLoggerFactory ?? new NullLoggerFactory()).GetLogger <CorrelateIncomingMessageStep>(); }
/// <summary> /// Executes the <paramref name="correlatedTask"/> with its own <see cref="CorrelationContext"/>. /// </summary> /// <typeparam name="T">The return type of the awaitable task.</typeparam> /// <param name="asyncCorrelationManager">The async correlation manager.</param> /// <param name="correlationId">The correlation id to use, or null to generate a new one.</param> /// <param name="correlatedTask">The task to execute.</param> /// <returns>An awaitable that completes with a result <typeparamref name="T"/> once the <paramref name="correlatedTask"/> has executed and the correlation context has disposed.</returns> /// <remarks> /// When logging and tracing are both disabled, no correlation context is created and the task simply executed as it normally would. /// </remarks> public static Task <T> CorrelateAsync <T>(this IAsyncCorrelationManager asyncCorrelationManager, string correlationId, Func <Task <T> > correlatedTask) { return(asyncCorrelationManager.CorrelateAsync(correlationId, correlatedTask, null)); }
/// <summary> /// Executes the <paramref name="correlatedTask"/> with its own <see cref="CorrelationContext"/>. /// </summary> /// <typeparam name="T">The return type of the awaitable task.</typeparam> /// <param name="asyncCorrelationManager">The async correlation manager.</param> /// <param name="correlatedTask">The task to execute.</param> /// <param name="onException">A delegate to handle the exception inside the correlation scope, before it is disposed. Returns <see langword="true" /> to consider the exception handled, or <see langword="false" /> to throw.</param> /// <returns>An awaitable that completes with a result <typeparamref name="T"/> once the <paramref name="correlatedTask"/> has executed and the correlation context has disposed.</returns> /// <remarks> /// When logging and tracing are both disabled, no correlation context is created and the task simply executed as it normally would. /// </remarks> public static Task <T> CorrelateAsync <T>(this IAsyncCorrelationManager asyncCorrelationManager, Func <Task <T> > correlatedTask, OnException <T> onException) { return(asyncCorrelationManager.CorrelateAsync(null, correlatedTask, onException)); }
/// <summary> /// Executes the <paramref name="correlatedTask"/> with its own <see cref="CorrelationContext"/>. /// </summary> /// <typeparam name="T">The return type of the awaitable task.</typeparam> /// <param name="asyncCorrelationManager">The async correlation manager.</param> /// <param name="correlatedTask">The task to execute.</param> /// <returns>An awaitable that completes with a result <typeparamref name="T"/> once the <paramref name="correlatedTask"/> has executed and the correlation context has disposed.</returns> /// <remarks> /// When logging and tracing are both disabled, no correlation context is created and the task simply executed as it normally would. /// </remarks> public static Task <T> CorrelateAsync <T>(this IAsyncCorrelationManager asyncCorrelationManager, Func <Task <T> > correlatedTask) { return(asyncCorrelationManager.CorrelateAsync(null, correlatedTask)); }