Exemplo n.º 1
0
 public DiagnosticObserver(
     DiagnosticObserverOptions <TDiagnosticHandler> options,
     TDiagnosticHandler handler)
 {
     _options = options;
     _handler = handler;
 }
Exemplo n.º 2
0
        public static IServiceCollection AddDiagnosticObserver <TDiagnosticHandler>(this IServiceCollection services,
                                                                                    Action <DiagnosticObserverOptions <TDiagnosticHandler> > configure)
            where TDiagnosticHandler : class, IDiagnosticHandler
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            services.TryAddTransient <DiagnosticObserverOptions <TDiagnosticHandler> >(serviceProvider =>
            {
                var options = new DiagnosticObserverOptions <TDiagnosticHandler>();
                configure(options);

                return(options);
            });

            services.TryAddTransient <TDiagnosticHandler>();

            services.TryAddEnumerable(
                ServiceDescriptor.Transient <IDiagnosticObserver, DiagnosticObserver <TDiagnosticHandler> >());

            return(services);
        }