private static HttpCorrelationInfoOptions CreateHttpCorrelationOptions(CorrelationInfoOptions options) { if (options is null) { return(new HttpCorrelationInfoOptions()); } return(new HttpCorrelationInfoOptions { Operation = { GenerateId = options.Operation.GenerateId, HeaderName = options.Operation.HeaderName, IncludeInResponse = options.Operation.IncludeInResponse }, Transaction = { GenerateId = options.Transaction.GenerateId, HeaderName = options.Transaction.HeaderName, IncludeInResponse = options.Transaction.IncludeInResponse, AllowInRequest = options.Transaction.AllowInRequest, GenerateWhenNotSpecified = options.Transaction.GenerateWhenNotSpecified } }); }
/// <summary> /// Initializes a new instance of the <see cref="CorrelationMiddleware"/> class. /// </summary> /// <param name="next">The next functionality in the request pipeline to be executed.</param> /// <param name="options">The options controlling how the correlation should happen.</param> /// <param name="logger">The logger to trace diagnostic messages during the correlation.</param> /// <exception cref="ArgumentNullException">When any of the parameters are <c>null</c>.</exception> /// <exception cref="ArgumentException">When the <paramref name="options"/> doesn't contain a non-<c>null</c> <see cref="IOptions{TOptions}.Value"/></exception> public CorrelationMiddleware( RequestDelegate next, IOptions <CorrelationInfoOptions> options, ILogger <CorrelationMiddleware> logger) { Guard.NotNull(next, nameof(next), "Requires a continuation delegate"); Guard.NotNull(options, nameof(options), "Requires a set of correlation options to manipulate how the correlation should happen"); Guard.NotNull(logger, nameof(logger), "Requires a logging implementation to trace diagnostic messages during the correlation"); Guard.For <ArgumentException>(() => options.Value is null, "Requires a set of correlation options to manipulate how the correlation should happen"); _next = next; _options = options.Value; _logger = logger; }
/// <summary> /// Initializes a new instance of the <see cref="HttpCorrelation"/> class. /// </summary> /// <param name="options">The options controlling how the correlation should happen.</param> /// <param name="correlationInfoAccessor">The instance to set and retrieve the <see cref="CorrelationInfo"/> instance.</param> /// <param name="logger">The logger to trace diagnostic messages during the correlation.</param> /// <param name="httpContextAccessor">The instance to have access to the current HTTP context.</param> /// <exception cref="ArgumentNullException">When any of the parameters are <c>null</c>.</exception> /// <exception cref="ArgumentException">When the <paramref name="options"/> doesn't contain a non-<c>null</c> <see cref="IOptions{TOptions}.Value"/></exception> public HttpCorrelation( IOptions <CorrelationInfoOptions> options, IHttpContextAccessor httpContextAccessor, ICorrelationInfoAccessor correlationInfoAccessor, ILogger <HttpCorrelation> logger) { Guard.NotNull(options, nameof(options), "Requires a set of options to configure the correlation process"); Guard.NotNull(httpContextAccessor, nameof(httpContextAccessor), "Requires a HTTP context accessor to get the current HTTP context"); Guard.NotNull(correlationInfoAccessor, nameof(correlationInfoAccessor), "Requires a correlation info instance to set and retrieve the correlation information"); Guard.NotNull(logger, nameof(logger), "Requires a logger to write diagnostic messages during the correlation"); Guard.NotNull(options.Value, nameof(options.Value), "Requires a value in the set of options to configure the correlation process"); _httpContextAccessor = httpContextAccessor; _options = options.Value; _correlationInfoAccessor = correlationInfoAccessor; _logger = logger; }