示例#1
0
        /// <summary>
        /// Registers correlation emitter.
        /// </summary>
        /// <remarks>
        /// Provided implementation of correlation emitter is registered as singleton.
        /// </remarks>
        /// <typeparam name="T">Implementing type of correlation emitter.</typeparam>
        /// <param name="builder">Correlator builder.</param>
        /// <returns>
        /// Correlator builder.
        /// </returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException">Thrown when trying to register correlation emitter second time.</exception>
        public static ICorrelatorBuilder WithCorrelationEmitter <T>(this ICorrelatorBuilder builder)
            where T : class, ICorrelationEmitter
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (builder.Services.Any(svc => svc.ServiceType == typeof(ICorrelationEmitter)))
            {
                throw new InvalidOperationException(
                          $"Correlation emitter ({typeof(ICorrelationEmitter).FullName}) has been already registered, remove default registration or ensure registration happens only once.");
            }

            builder.Services.AddSingleton <ICorrelationEmitter, T>();

            return(builder);
        }
示例#2
0
        /// <summary>
        /// Registers correlation validator.
        /// </summary>
        /// <typeparam name="T">Implementing type of correlation validator.</typeparam>
        /// <param name="builder">Correlator builder.</param>
        /// <param name="validator">Instance of correlation validator.</param>
        /// <returns>
        /// Correlator builder.
        /// </returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException">Thrown when trying to register correlation validator second time.</exception>
        public static ICorrelatorBuilder WithValidator <T>(this ICorrelatorBuilder builder, T validator)
            where T : ICorrelationValidator
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (builder.Services.Any(svc => svc.ServiceType == typeof(ICorrelationValidator)))
            {
                throw new InvalidOperationException(
                          $"Correlation validator ({typeof(ICorrelationValidator).FullName} -> {typeof(T).FullName}) has been already registered, only one validator is supported.");
            }

            builder.Services.AddSingleton <ICorrelationValidator>(validator);

            return(builder);
        }
示例#3
0
 /// <summary>
 /// Registers correlation emitter.
 /// </summary>
 /// <param name="builder">Correlator builder.</param>
 /// <returns>
 /// Correlator builder.
 /// </returns>
 public static ICorrelatorBuilder WithDefaultCorrelationEmitter(this ICorrelatorBuilder builder) =>
 builder.WithCorrelationEmitter <CorrelationEmitter>();
示例#4
0
 /// <summary>
 /// Registers default implementation of correlation context factory.
 /// </summary>
 /// <param name="builder">Correlator builder.</param>
 /// <returns>
 /// Correlator builder.
 /// </returns>
 public static ICorrelatorBuilder WithDefaultCorrelationContextFactory(this ICorrelatorBuilder builder) =>
 builder.WithCorrelationContextFactory <CorrelationContextFactory>();