/// <inheritdoc /> protected override void ConfigureFeature(IServiceCollection services, IAppFeatureCollection features) { var options = Options.Value; services.AddOptions <ScribanOptions>() .ValidateDataAnnotations(); services.TryAddSingleton <ITemplateEngine, ScribanTemplateEngine>(); services.AddSingleton <ITemplatesStore>( sp => new FileSystemTemplatesStore(options.Templates.Store.FileSystem.Path)); if (options.Subscriptions.Store.UseInMemoryStore) { services.AddSingleton <ISubscriptionsStore, InMemorySubscriptionsStore>(); } else if (options.Subscriptions.Store.Consul != null) { services.AddConsulSubscriptions(Configuration.CreateBinder <ConsulOptions>( "Alerting:Subscriptions:Store:Consul", required: true)); } else if (options.Subscriptions.Store.Faster != null) { services.AddFasterSubscriptions(Configuration.CreateBinder <FasterStoreOptions>( "Alerting:Subscriptions:Store:Faster", required: true)); } if (options.Channels.Store.Predefined != null) { services.AddSingleton <IChannelStore>(sp => new InMemoryChannelStore( options.Channels.Store.Predefined)); } }
/// <inheritdoc /> protected override void ConfigureFeature(IServiceCollection services, IAppFeatureCollection features) { services.AddMetrics(s => { s.Configuration.Configure(cfg => { cfg.AddEnvTag(); cfg.DefaultContextLabel = Options.Value.Prefix; }); s.OutputMetrics.AsPrometheusPlainText(); }); services.AddMetricsEndpoints(o => { o.MetricsTextEndpointEnabled = false; o.MetricsEndpointEnabled = true; o.MetricsEndpointOutputFormatter = o.MetricsOutputFormatters .OfType <MetricsPrometheusTextOutputFormatter>() .First(); }); services.AddTransient <IMetricsCollector, ActiveSubscriptionsMetricsCollector>(); }
public static IAppFeatureCollection AddWhen<TFeature, TOptions>(this IAppFeatureCollection builder, Func<bool> predicate, Action<TOptions> configure) where TFeature : class, IAppFeature<TOptions> where TOptions : class, new() { if (!predicate()) return builder; var options = new AppFeatureOptions<TOptions>(configure); var feature = ActivatorUtilities.CreateInstance<TFeature>(builder.ServiceProvider, (IOptions<TOptions>) options); var enabled = feature.Configure(builder.Services, builder); if (enabled) { var subscriptions = builder.ServiceProvider.GetRequiredService<AppFeatureEventSubscriptions>(); foreach (var subscription in subscriptions.Get<TFeature, TOptions>()) { subscription.Notify(options.Value); } } builder.Services.TryAddSingleton(feature); builder.Services.AddOptions<TOptions>() .Configure(configure) .ValidateDataAnnotations(); var logger = builder.ServiceProvider.GetLogger<TFeature>(); if (enabled) logger?.LogInformation($"Pipeline: Feature '{typeof(TFeature).Name}' registered successfully"); return builder; }
/// <inheritdoc /> protected override void ConfigureFeature(IServiceCollection services, IAppFeatureCollection features) { const string clientName = "telegram.client"; var options = Options.Value; services.AddHttpClient(clientName) .ConfigureHttpClient((sp, cl) => {}) .ConfigurePrimaryHttpMessageHandler(sp => { var proxy = options.Proxy?.CreateProxy(); return(new HttpClientHandler { UseProxy = proxy != null, Proxy = proxy }); }); services.AddSingleton <IRequestHandlerFinder>(new RequestHandlerFinder(services)); services.AddSingleton <ITelegramBotClient>(sp => { var client = sp.GetHttpClient(clientName); return(new TelegramBotClient(options.Token, client)); }); services.AddHostedService <BotUpdatesPollingService>(); services.AddTransient <IBotActionContextAccessor, BotActionContextAccessor>(); services.AddTransient <IBotUserProvider, BotUserProvider>(); services.AddSingleton <IBotPollingUpdatesReceiver, BotPollingUpdatesReceiver>(); }
/// <inheritdoc /> protected override void ConfigureFeature(IServiceCollection services, IAppFeatureCollection features) { var options = Options.Value; services.TryAddSingleton <IHealthCheckResponseWriter, SystemJsonHealthCheckResponseWriter>(); var builder = services.AddHealthChecks(); features .WhenConfigured <AlertingFeature, AlertingFeatureOptions>(o => { var consulOptions = o.Subscriptions.Store.Consul; if (consulOptions != null) { var urlInfo = new UriBuilder(consulOptions.Address); builder.AddConsul(co => { co.HostName = urlInfo.Host; co.Port = urlInfo.Port; }, name: "consul", options.Consul?.FailureStatus, timeout: options.Consul?.Timeout); } }) .WhenConfigured <BotFeature, BotFeatureOptions>(o => { var registration = new HealthCheckRegistration( name: "telegram", factory: sp => new TelegramHealthCheck(sp.GetRequiredService <ITelegramBotClient>()), failureStatus: options.Telegram.FailureStatus, tags: default,
/// <inheritdoc /> protected override void ConfigureFeature(IServiceCollection services, IAppFeatureCollection features) { services.AddTransient <IConfigureOptions <SwaggerGenOptions>, ConfigureSwaggerGenOptions>(); services.AddSwaggerGen(s => { s.OperationFilter <SwaggerDefaultValues>(); var includeDocsTypesMarkers = new[] { typeof(BotController), typeof(AlertManagerWebhookUpdate), typeof(Update) }; foreach (var marker in includeDocsTypesMarkers) { var xmlName = $"{marker.Assembly.GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlName); if (File.Exists(xmlPath)) { s.IncludeXmlComments(xmlPath); } } }); }
public static IAppFeatureCollection WhenConfigured<TFeature, TOptions>(this IAppFeatureCollection features, Action<TOptions> callback) where TFeature : class, IAppFeature<TOptions> where TOptions : class, new() { var subscriptions = features.ServiceProvider.GetRequiredService<AppFeatureEventSubscriptions>(); subscriptions.Add(new AppFeatureSubscription<TFeature, TOptions>(callback)); return features; }
/// <inheritdoc /> public bool Configure(IServiceCollection services, IAppFeatureCollection features) { if (Options.Value.Enabled) { ConfigureFeature(services, features); } var isOverriden = _methodHolder.ConfigureFeature.IsOverriden(); return(Options.Value.Enabled && isOverriden); }
/// <inheritdoc /> protected override void ConfigureFeature(IServiceCollection services, IAppFeatureCollection features) { if (Options.Value.OrphanNotifications != null) { services.AddCronJob <OrphanSubscriptionsCleanupJob>(o => { o.UseLocalTimeZone = false; o.Schedule = Options.Value.OrphanNotifications.Schedule; }); } }
/// <inheritdoc /> protected override void ConfigureFeature(IServiceCollection services, IAppFeatureCollection features) { var options = Options.Value; services.AddMemoryCache(); services.AddMiniProfiler(o => { o.RouteBasePath = options.Path; }); services.AddDiagnosticObserver <HttpClientProfilingDiagnosticObserver>(); services.Decorate <IStringLocalizerFactory, ProfilingStringLocalizerFactory>(); }
public static IAppFeatureCollection Add<TFeature>(this IAppFeatureCollection builder) where TFeature : class, IAppFeature { var feature = ActivatorUtilities.CreateInstance<TFeature>(builder.ServiceProvider); var enabled = feature.Configure(builder.Services, builder); builder.Services.TryAddSingleton(feature); var logger = builder.ServiceProvider.GetLogger<TFeature>(); if (enabled) logger?.LogInformation($"Services: Feature '{typeof(TFeature).Name}' registered successfully"); return builder; }
/// <inheritdoc /> protected override void ConfigureFeature(IServiceCollection services, IAppFeatureCollection features) { services .AddApiVersioning(o => { o.ReportApiVersions = true; }) .AddVersionedApiExplorer(); services.AddHttpContextAccessor(); services.AddControllers() .AddJsonOptions(o => { o.JsonSerializerOptions.IgnoreNullValues = true; o.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }); }
public static IAppFeatureCollection AddFromConfiguration <TFeature, TOptions>(this IAppFeatureCollection builder, string sectionName, bool required = true, bool addAlways = false) where TFeature : class, IAppFeature <TOptions> where TOptions : class, new() { var configuration = builder.ServiceProvider.GetRequiredService <IConfiguration>(); return(required ? builder.Add <TFeature, TOptions>( configuration.CreateBinder <TOptions>(sectionName, required: true)) : builder.AddWhen <TFeature, TOptions>( () => configuration.SectionExists(sectionName) || addAlways, configuration.CreateBinder <TOptions>(sectionName, required: false))); }
/// <inheritdoc /> protected override void ConfigureFeature(IServiceCollection services, IAppFeatureCollection features) { void RegisterKafkaTransport <TMessage, TConsumer>(IKafkaTransportBuilder builder, TransportFeatureOptions.KafkaTransportOptions.TransportOptions transportOptions) where TConsumer : class, ITransportConsumer <TMessage>
protected virtual void ConfigureFeature(IServiceCollection services, IAppFeatureCollection features) { }
/// <inheritdoc /> public bool Configure(IServiceCollection services, IAppFeatureCollection features) { ConfigureFeature(services, features); return(_methodHolder.ConfigureFeature.IsOverriden()); }
public static bool IsEnabled<TFeature>(this IAppFeatureCollection builder) where TFeature : IAppFeature { return builder.Services.Any(s => s.ServiceType == typeof(TFeature)); }