예제 #1
0
        void ConfigureDependencyInjection(IServiceCollection services, IWebHostEnvironment env)
        {
            services.AddLogging(loggingBuilder =>
            {
                loggingBuilder.AddConfiguration(Configuration.GetSection("Logging"));
                loggingBuilder.AddConsole();

                if (env.IsDevelopment())
                {
                    loggingBuilder.AddDebug();
                }
            });
#if DEBUG
            //services.AddApplicationInsightsTelemetry();
#endif
            services.AddScoped <IBloggingRepository, BloggingRepository>();

            string dbs_config;
#if INCLUDE_COSMOSDB
            if (Configuration.GetSection("CosmosDB")?["enabled"] == true.ToString())
            {
                services.AddScoped <IHashesRepositoryPure, ThinHashesDocumentDBRepository>(serviceProvider =>
                {
                    var conf            = Configuration.GetSection("CosmosDB");
                    string endpoint     = conf["Endpoint"];
                    string key          = conf["Key"];
                    string databaseId   = conf["DatabaseId"];
                    string collectionId = conf["CollectionId"];

                    var db = new ThinHashesDocumentDBRepository(endpoint, key, databaseId, collectionId);
                    return(db);
                });
                dbs_config = Configuration["DBKind"]?.ToLower() + "+CosmosDB";

                services.AddScoped <IThinHashesDocumentDBRepository, ThinHashesDocumentDBRepository>();
            }
            else
#endif
            {
                services.AddScoped <IHashesRepositoryPure, HashesRepository>();
                dbs_config = Configuration["DBKind"]?.ToLower();
            }
            services.Configure <DBConfigShower>(options =>
            {
                options.DBConfig = dbs_config;
            });
            services.Configure <EmailSettings>(Configuration.GetSection("EmailSettings"));

            //1st time init of static vars
            HashesRepository.HashesInfoExpirationInMinutes = TimeSpan.FromMinutes(Configuration.GetValue <int>(nameof(HashesRepository.HashesInfoExpirationInMinutes)));

            //services.AddSingleton<IUrlHelperFactory, DomainUrlHelperFactory>();
            services.AddHostedService <BackgroundOperationService>();
            services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>(CreateBackgroundTaskQueue);
            services.AddServerTiming();

            services.AddTransient <MjpgStreamerHttpClientHandler>()
            .AddHttpClient <IMjpgStreamerHttpClient, MjpgStreamerHttpClient>()
            .ConfigurePrimaryHttpMessageHandler <MjpgStreamerHttpClientHandler>();
        }
예제 #2
0
        public CosmosDBHasher(IConfigurationSection conf)
        {
            if (conf == null)
            {
                throw new NullReferenceException("bad config");
            }

            string endpoint     = conf["Endpoint"];
            string key          = conf["Key"];
            string databaseId   = conf["DatabaseId"];
            string collectionId = conf["CollectionId"];

            _db = new ThinHashesDocumentDBRepository(endpoint, key, databaseId, collectionId);
        }