/// <summary> /// Adds to IoC service for working with date and time via database. /// </summary> /// <param name="serviceCollection"></param> /// <param name="dbDateTimeOptions"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> public static IServiceCollection AddDbSyncDateTimeServices( this IServiceCollection serviceCollection, DbDateTimeOptions dbDateTimeOptions) { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } return(serviceCollection.AddDbSyncDateTimeServices <DbSyncDateTimeService>(dbDateTimeOptions)); }
public DbDateTimeSynchronizationWatchdog( DbDateTimeOptions dbDateTimeOptions, T dateTimeService, ILogger <DbDateTimeSynchronizationWatchdog <T> > logger) { _dbDateTimeOptions = dbDateTimeOptions ?? throw new ArgumentNullException(nameof(dbDateTimeOptions)); _dbDateTimeOptions.AssertValid(); _dateTimeService = dateTimeService ?? throw new ArgumentNullException(nameof(dateTimeService)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
/// <summary> /// Adds to IoC service for working with date and time via database. /// </summary> /// <param name="serviceCollection"></param> /// <param name="dbDateTimeOptions"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> public static IServiceCollection AddDbSyncDateTimeServices <T>( this IServiceCollection serviceCollection, DbDateTimeOptions dbDateTimeOptions) where T : DbSyncDateTimeService { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } if (dbDateTimeOptions == null) { throw new ArgumentNullException(nameof(dbDateTimeOptions)); } serviceCollection.TryAddSingleton(dbDateTimeOptions); serviceCollection.TryAddSingleton <T>(); serviceCollection.TryAddSingleton <IDateTimeService>(s => s.GetRequiredService <T>()); serviceCollection.AddAppInitializer <DateTimeServiceInitializer <T> >(); serviceCollection.AddSingleton <IHostedService, DbDateTimeSynchronizationWatchdog <T> >(); return(serviceCollection); }