Ejemplo n.º 1
0
        /// <summary>
        /// Adds an Aika historian service to the specified services container.
        /// </summary>
        /// <typeparam name="T">The <see cref="IHistorian"/> implementation to use with the <see cref="AikaHistorian"/>.</typeparam>
        /// <param name="services">The services container to add the historian service to.</param>
        /// <param name="historianFactory">The factory to create the singleton instance of <typeparamref name="T"/> with.</param>
        /// <param name="options">The Aika service options.</param>
        /// <returns>
        /// The <paramref name="services"/> container, to allow chaining.
        /// </returns>
        public static IServiceCollection AddAikaHistorian <T>(this IServiceCollection services, Func <IServiceProvider, T> historianFactory, AikaServiceOptions options) where T : class, IHistorian
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            services.AddSingleton <TaskRunner>();
            services.AddSingleton <IHostedService>(x => x.GetService <TaskRunner>());
            services.AddSingleton <ITaskRunner>(x => x.GetService <TaskRunner>());

            if (historianFactory == null)
            {
                services.AddSingleton <IHistorian, T>();
            }
            else
            {
                services.AddSingleton <IHistorian, T>(historianFactory);
            }
            services.AddSingleton <AikaHistorian>();

            services.AddSingleton <IHostedService, AikaService>(x => {
                var aika = x.GetService <AikaHistorian>();
                return(new AikaService(aika, options ?? new AikaServiceOptions(), x.GetService <ILogger <AikaService> >()));
            });

            return(services);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new <see cref="AikaService"/> object.
 /// </summary>
 /// <param name="aika">The <see cref="AikaHistorian"/> to initialize.</param>
 /// <param name="options">The service options.</param>
 /// <param name="logger">The logger for the service.</param>
 /// <exception cref="ArgumentNullException"><paramref name="aika"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="options"/> is <see langword="null"/>.</exception>
 internal AikaService(AikaHistorian aika, AikaServiceOptions options, ILogger <AikaService> logger)
 {
     _aika    = aika ?? throw new ArgumentNullException(nameof(aika));
     _options = options ?? throw new ArgumentNullException(nameof(options));
     _logger  = logger;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds an Aika historian service to the specified services container.
 /// </summary>
 /// <typeparam name="T">The <see cref="IHistorian"/> implementation to use with the <see cref="AikaHistorian"/>.</typeparam>
 /// <param name="services">The services container to add the historian service to.</param>
 /// <param name="options">The Aika service options.</param>
 /// <returns>
 /// The <paramref name="services"/> container, to allow chaining.
 /// </returns>
 public static IServiceCollection AddAikaHistorian <T>(this IServiceCollection services, AikaServiceOptions options) where T : class, IHistorian
 {
     return(services.AddAikaHistorian <T>(null, options));
 }