httpflow icon indicating copy to clipboard operation
httpflow copied to clipboard

Using connection string from appsettings.json in StartupSetup.

Open zn opened this issue 6 years ago • 1 comments

Hello everyone! In StartupSetup the connection string is hard-coded. What if I want to use one from appsettings.json? Is it ok if I'll add a parameter connectionString to your method:

public static void AddDbContext(this IServiceCollection services, string connectionString) =>
            services.AddDbContext<AppDbContext>(options =>
                options.UseSqlServer(connectionString));

And just pass the connection string as an argument from Startup?

services.AddDbContext(Configuration.GetConnectionString("DefaultConnection"));

zn avatar Feb 23 '20 12:02 zn

Yes, I'll fix that unless someone beats me to it.

ardalis avatar Apr 24 '20 17:04 ardalis