コード例 #1
0
        async Task ConfigureServicesAsync(IServiceCollection services)
        {
            string aspNetDb         = null;
            var    aspNetDbLocation = new AspNetDbLocation();

            try
            {
                var getAspNetDb = await aspNetDbLocation.GetAspNetDbAsync(EndpointInstance);

                aspNetDb = getAspNetDb.AspNetDb;
            }
            catch (Exception e)
            {
                //Do nothing
            }
            if (aspNetDb != null)
            {
                services.AddDbContext <ApplicationDbContext>(options =>
                                                             options.UseSqlite("Data Source=" + aspNetDb));
            }
            else
            {
                services.AddDbContext <ApplicationDbContext>(options =>
                                                             options.UseSqlite("Data Source=" + Directory.GetCurrentDirectory() + "\\App_Data\\AspNet.db"));
            }
        }
コード例 #2
0
        public async Task ConfigureServicesAsync(IServiceCollection services)
        {
            string sqlServerConnectionString = null;
            var    aspNetDbLocation          = new AspNetDbLocation();

            try
            {
                sqlServerConnectionString = await aspNetDbLocation.GetAspNetDbAsync(Configuration.GetSection("ConnectionStrings:ApiAddress").Get <string>());
            }
            catch (Exception e)
            {
                //Do nothing
            }
            if (sqlServerConnectionString != null)
            {
                services.AddDbContext <ApplicationDbContext>(options =>
                                                             options.UseSqlServer(sqlServerConnectionString));
            }
            else
            {
                services.AddDbContext <ApplicationDbContext>(options =>
                                                             options.UseSqlite("Data Source=" + Directory.GetCurrentDirectory() + "\\App_Data\\AspNet.db"));
            }
        }