Exemplo n.º 1
0
        public DatabaseHarness()
        {
            _dbConnection = SqlLiteUtils.CreateInMemoryDatabase();

            _databaseOptions = new DbContextOptionsBuilder <CovidDataContext>()
                               .UseSqlite(_dbConnection)
                               .Options;

            _dbInitialized = false;
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.AddHttpClient();
            services.AddTransient <CovidTrackingProjectImport>();
            services.AddSingleton <ICovidTrackingDataService, CovidTrackingDataService>();

            // Services for initialization
            services.AddHostedService <CovidDataContextInitializationService>();
            services.AddHostedService <CovidTrackingProjectImportService>();

            services.AddOpenApiDocument(d =>
            {
                d.DocumentName = "hs-covid-19-v1";
                d.Title        = "Honlsoft COVID-19 API";
                d.Description  = "Data from the COVID-19 Tracking Project aggregated in different ways to support API access.";
                d.Version      = "v1";
            });

            // We'll create a single database connect, that will be used while the application is running.
            // it will be maintained in memory.  Will have to watch memory usage to see how it handles it.
            var database = SqlLiteUtils.CreateInMemoryDatabase();

            Action <DbContextOptionsBuilder> dbOptions = (opts) =>
            {
                opts.UseSqlite(database);
            };

            // The DB context needs to be set as a singleton, otherwise EF core get's confused between the two following calls.
            services.AddDbContext <CovidDataContext>(dbOptions, optionsLifetime: ServiceLifetime.Singleton);
            services.AddDbContextFactory <CovidDataContext>(dbOptions);

            // In production, the React files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/build";
            });
        }