コード例 #1
0
 public async Task InvokeAsync(HttpContext context, ICorrelationIdAccessor correlationIdAccessor)
 {
     using (LogContext.Push(new CorrelationIdEnricher(correlationIdAccessor)))
     {
         await _next(context);
     }
 }
コード例 #2
0
ファイル: CorrelationIdTests.cs プロジェクト: fgcp020/Clay
        public static void CorrelationId_From_lambda_returns_value()
        {
            // Act
            ICorrelationIdAccessor accessor = CorrelationId.From(() => Guid.NewGuid().ToString("D", CultureInfo.InvariantCulture));

            // Assert
            Assert.True(Guid.TryParse(accessor.CorrelationId, out _));
        }
コード例 #3
0
        public EventStore(DbContextOptions options, IDateTime dateTime, ICorrelationIdAccessor correlationIdAccessor)
            : base(options)
        {
            ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

            _dateTime = dateTime;
            _correlationIdAccessor = correlationIdAccessor;
        }
コード例 #4
0
ファイル: CorrelationIdTests.cs プロジェクト: fgcp020/Clay
        public static void CorrelationId_From_string_returns_value(string expected)
        {
            // Arrange
            ICorrelationIdAccessor accessor = CorrelationId.From(expected);

            // Act
            var actual = accessor.CorrelationId;

            // Assert
            Assert.Equal(expected, actual);
        }
 public IdentifyingHttpServerEventCallback(
     ISessionIdAccessor sessionIdAccessor,
     ICorrelationIdAccessor correlationIdAccessor,
     IInboundRequestIdAccessor inboundRequestIdAccessor,
     IApplicationInfo applicationInfo)
 {
     _sessionIdAccessor        = sessionIdAccessor ?? throw new ArgumentNullException(nameof(sessionIdAccessor));
     _correlationIdAccessor    = correlationIdAccessor ?? throw new ArgumentNullException(nameof(correlationIdAccessor));
     _inboundRequestIdAccessor = inboundRequestIdAccessor ?? throw new ArgumentNullException(nameof(inboundRequestIdAccessor));
     _applicationInfo          = applicationInfo ?? throw new ArgumentNullException(nameof(applicationInfo));
 }
コード例 #6
0
ファイル: CorrelationIdTests.cs プロジェクト: fgcp020/Clay
        public static void CorrelationId_From_guid_returns_value()
        {
            // Arrange
            var expected = Guid.NewGuid();
            ICorrelationIdAccessor accessor = CorrelationId.From(expected);

            // Act
            var actual = Guid.Parse(accessor.CorrelationId);

            // Assert
            Assert.Equal(expected, actual);
        }
        public CorrelationIdHandlerTests()
        {
            _correlationIdAccessor = A.Fake <ICorrelationIdAccessor>();

            _underTest = new CorrelationIdHandler(_correlationIdAccessor)
            {
                InnerHandler = new DummyInnerHandler()
            };

            _invoker = new HttpMessageInvoker(_underTest);
            _request = new HttpRequestMessage(HttpMethod.Get, "http://foo.com");
        }
 public TaggingHttpClientDecorator(
     ISessionIdAccessor sessionIdAccessor,
     ICorrelationIdAccessor correlationIdAccessor,
     IOutboundRequestIdAccessor outboundRequestIdAccessor,
     IGenerateGuids guidGenerator,
     IApplicationInfo applicationInfo)
 {
     _sessionIdAccessor         = sessionIdAccessor;
     _correlationIdAccessor     = correlationIdAccessor;
     _outboundRequestIdAccessor = outboundRequestIdAccessor;
     _guidGenerator             = guidGenerator;
     _applicationInfo           = applicationInfo;
 }
コード例 #9
0
        protected RepositoryBase(ILogger Logger, ICorrelationIdAccessor CorrelationIdAccessor, ILoggedDatabase Database)
        {
            this.Logger     = Logger;
            CorrelationId   = CorrelationIdAccessor.GetCorrelationId();
            _database       = Database;
            GetContextAsync = async() =>
            {
                // Return a new, unshared database connection.
                // Unit of Work classes should modify this Func to return a shared (by multiple repositories) database connection.
                var connection = await _database.OpenConnectionAsync(CorrelationId);

                var transaction = connection.BeginTransaction();
                return(new RepositoryContext(connection, transaction, true, true));
            };
        }
コード例 #10
0
 public static IHttpClient AddTagging(
     this IHttpClient httpClient,
     ISessionIdAccessor sessionIdAccessor,
     ICorrelationIdAccessor correlationIdAccessor,
     IOutboundRequestIdAccessor outboundRequestIdAccessor,
     IGenerateGuids guidGenerator,
     IApplicationInfo applicationInfo)
 {
     return(new TaggingHttpClient(
                httpClient,
                sessionIdAccessor,
                correlationIdAccessor,
                outboundRequestIdAccessor,
                guidGenerator,
                applicationInfo));
 }
コード例 #11
0
        public TaggingHttpClient(
            IHttpClient httpClient,
            ISessionIdAccessor sessionIdGetter,
            ICorrelationIdAccessor correlationIdGetter,
            IOutboundRequestIdAccessor outboundRequestIdAccessor,
            IGenerateGuids guidGenerator,
            IApplicationInfo applicationInfo)
        {
            _httpClient                = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
            _sessionIdAccessor         = sessionIdGetter ?? throw new ArgumentNullException(nameof(sessionIdGetter));
            _correlationIdAccessor     = correlationIdGetter ?? throw new ArgumentNullException(nameof(correlationIdGetter));
            _outboundRequestIdAccessor = outboundRequestIdAccessor ?? throw new ArgumentNullException(nameof(outboundRequestIdAccessor));
            _guidGenerator             = guidGenerator ?? throw new ArgumentNullException(nameof(guidGenerator));

            if (applicationInfo == null)
            {
                throw new ArgumentNullException(nameof(applicationInfo));
            }

            _userAgent = BuildUserAgent(applicationInfo);
        }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CorrelationIdContextProvider"/> class.
 /// </summary>
 /// <param name="accessor">The accessor used to retreive the correlation id.</param>
 public CorrelationIdContextProvider(ICorrelationIdAccessor accessor)
 {
     Accessor = accessor;
 }
コード例 #13
0
 public EventSourcingDistilledDbContext(DbContextOptions options, IDateTime dateTime, ICorrelationIdAccessor correlationIdAccessor)
     : base(options, dateTime, correlationIdAccessor)
 {
     ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
 }
コード例 #14
0
        public static DisposableHttpClient CreateClientWithTagging(this StubHttpApi api, ISessionIdAccessor sessionIdAccessor, ICorrelationIdAccessor correlationIdAccessor, IOutboundRequestIdAccessor outboundRequestIdAccessor, IGenerateGuids guidGenerator, IApplicationInfo applicationInfo, int timeoutMs = 3000)
        {
            var configuration = new InstrumentingConfiguration {
                Uri = api.BaseUri, TimeoutMs = timeoutMs
            };
            var httpClient = new DefaultHttpClient(configuration);

            return(new DisposableHttpClient(httpClient, httpClient.AddTagging(sessionIdAccessor, correlationIdAccessor, outboundRequestIdAccessor, guidGenerator, applicationInfo)));
        }
コード例 #15
0
 public DefaultHttpRequestMessageHandler(ICorrelationIdAccessor correlationIdAccessor)
 {
     this._correlationIdAccessor = correlationIdAccessor;
 }
コード例 #16
0
 public RequestHandler(ICorrelationIdAccessor correlationIdAccessor, IHttpContextAccessor httpContextAccessor)
 {
     this._correlationIdAccessor = correlationIdAccessor;
     this._httpContextAccessor   = httpContextAccessor;
 }
コード例 #17
0
        public async Task InvokeAsync(HttpContext context, ILogger <CorrelationIdMiddleware> logger, ICorrelationIdAccessor correlationIdAccessor)
        {
            var correlationIdCreated = false;

            var correlationId = context.Request.Headers[CorrelationIdHeaderName];

            if (correlationId == StringValues.Empty)
            {
                correlationId        = Guid.NewGuid().ToString();
                correlationIdCreated = true;
            }

            correlationIdAccessor.Set(correlationId.ToString());

            if (correlationIdCreated)
            {
                logger.LogDebug($"No {CorrelationIdLogName} found in header. Adding new {CorrelationIdLogName} {correlationId} to context");
            }
            else
            {
                logger.LogDebug($"{CorrelationIdLogName} {correlationId} found in header and added to context");
            }

            await _next(context);
        }
コード例 #18
0
 public CorrelationIdHandler(ICorrelationIdAccessor correlationIdAccessor)
 {
     _correlationIdAccessor = correlationIdAccessor ?? throw new ArgumentNullException(nameof(correlationIdAccessor));
 }
コード例 #19
0
 protected UnitOfWorkBase(ILogger Logger, ICorrelationIdAccessor CorrelationIdAccessor, ILoggedDatabase Database)
 {
     this.Logger   = Logger;
     CorrelationId = CorrelationIdAccessor.GetCorrelationId();
     _database     = Database;
 }
コード例 #20
0
 public EventStore(IEventStoreDbContext context, IDateTime dateTime, ICorrelationIdAccessor correlationIdAccessor)
 {
     _dateTime = dateTime;
     _context  = context;
     _correlationIdAccessor = correlationIdAccessor;
 }
 public CorrelationIdMessageHandler(ICorrelationIdAccessor correlationIdAccessor, ILogger <CorrelationIdMessageHandler> logger)
 {
     _correlationIdAccessor = correlationIdAccessor;
     _logger = logger;
 }
コード例 #22
0
 public CorrelationIdEnricher(ICorrelationIdAccessor correlationIdAccessor)
 {
     _correlationIdAccessor = correlationIdAccessor;
 }