Exemplo n.º 1
0
        /// <summary>
        /// Adds the configuration used to configure Punctual
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static IPunctualBuilder AddConfiguration(this IPunctualBuilder builder, IConfiguration configuration)
        {
            builder.AddConfiguration();
            builder.Services.AddSingleton(new PunctualConfiguration(configuration.GetSection("Punctual")));

            return(builder);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a new hosted service with options and the action to perform
        /// </summary>
        /// <typeparam name="THostedService"></typeparam>
        /// <typeparam name="THostedServiceOptions"></typeparam>
        /// <typeparam name="THostedServiceOptionsSetup"></typeparam>
        /// <typeparam name="TScheduledAction"></typeparam>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static IPunctualBuilder Add <THostedService, THostedServiceOptions, THostedServiceOptionsSetup, TScheduledAction>(this IPunctualBuilder builder)
            where THostedService : class, IHostedService <TScheduledAction>
            where THostedServiceOptions : class, IHostedServiceOptions
            where THostedServiceOptionsSetup : class, IConfigureOptions <THostedServiceOptions>
            where TScheduledAction : class, IScheduledAction
        {
            builder.AddConfiguration();
            builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <IConfigureOptions <THostedServiceOptions>, THostedServiceOptionsSetup>());
            builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <IOptionsChangeTokenSource <THostedServiceOptions>, HostedServiceOptionsChangeTokenSource <THostedServiceOptions, THostedService> >());
            builder.Services.TryAddTransient <TScheduledAction>();
            builder.Services.AddHostedService <THostedService>();

            return(builder);
        }