public static OperationsOptions AddInteractiveConsole( this OperationsOptions options, bool enabled = true) { EnsureArg.IsNotNull(options, nameof(options)); EnsureArg.IsNotNull(options.Context, nameof(options.Context)); if (options.Context.IsConsoleEnabled() && enabled) { Naos.Core.Common.Console2.WriteTextLogo(); // needed for mediator, register console commands + handlers options.Context.Services.Scan(scan => scan .FromApplicationDependencies() .AddClasses(classes => classes.Where(c => c.Name.EndsWith("ConsoleCommand") || c.Name.EndsWith("ConsoleCommandEventHandler"))) .AsImplementedInterfaces()); options.Context.Services.AddSingleton <Hosting.IHostedService>(sp => { return(new InteractiveConsoleHostedService( sp.GetRequiredService <ILoggerFactory>(), (IMediator)sp.CreateScope().ServiceProvider.GetService(typeof(IMediator)), sp.GetServices <IConsoleCommand>())); }); } return(options); }
public static OperationsOptions AddLogging( this OperationsOptions options, Action <LoggingOptions> optionsAction = null, string environment = null, string correlationId = null, LoggerConfiguration loggerConfiguration = null) { EnsureArg.IsNotNull(options, nameof(options)); EnsureArg.IsNotNull(options.Context, nameof(options.Context)); options.Context.Messages.Add($"{LogKeys.Startup} naos services builder: logging added"); internalCorrelationId = correlationId; var loggingOptions = new LoggingOptions( options.Context, loggerConfiguration ?? new LoggerConfiguration()); InitializeLogger(loggingOptions); optionsAction?.Invoke(loggingOptions); options.Context.Services.AddSingleton(sp => CreateLoggerFactory(loggingOptions)); options.Context.Services.AddSingleton(typeof(ILogger <>), typeof(LoggingAdapter <>)); options.Context.Services.AddSingleton(typeof(Logging.ILogger), typeof(LoggingAdapter)); options.Context.Services.AddTransient <HttpClientLogHandler>(); options.Context.Services.Replace(ServiceDescriptor.Singleton <IHttpMessageHandlerBuilderFilter, HttpClientLogHandlerBuilderFilter>()); return(options); }
public static OperationsOptions AddTracing( this OperationsOptions options, Action <OperationsTracingOptions> optionsAction = null) { EnsureArg.IsNotNull(options, nameof(options)); EnsureArg.IsNotNull(options.Context, nameof(options.Context)); options.Context.Messages.Add("naos services builder: tracing added"); options.Context.Services.AddScoped <ITracer>(sp => { return(new Tracer( new AsyncLocalScopeManager((IMediator)sp.CreateScope().ServiceProvider.GetService(typeof(IMediator))), sp.GetService <ISampler>())); }); options.Context.Services.AddScoped <HttpClientTracerHandler>(); if (optionsAction == null) { options.Context.Services.AddSingleton <ISampler, ConstantSampler>(); } else { optionsAction.Invoke(new OperationsTracingOptions(options.Context)); } //options.Context.Services.AddSingleton<ISampler>(sp => new OperationNamePatternSampler(new[] { "http*" })); // TODO: configure different samplers //options.Context.Services.AddSingleton<ISampler>(sp => new RateLimiterSampler(new RateLimiter(2.0, 2.0))); // TODO: configure different samplers return(options); }
public static OperationsOptions AddRequestStorage( this OperationsOptions options, Action <RequestStorageOptions> optionsAction = null) { EnsureArg.IsNotNull(options, nameof(options)); EnsureArg.IsNotNull(options.Context, nameof(options.Context)); optionsAction?.Invoke(new RequestStorageOptions(options.Context)); return(options); }
public static OperationsOptions AddSystemHealthChecks( this OperationsOptions options) { EnsureArg.IsNotNull(options, nameof(options)); EnsureArg.IsNotNull(options.Context, nameof(options.Context)); options.Context.Services.AddHealthChecks() .AddCheck <SystemMemoryHealthCheck>("operations-system-memory", tags: new[] { "naos" }) .AddCheck <SystemCpuHealthCheck>("operations-system-cpu", tags: new[] { "naos" }); return(options); }