Global connectionString

public class Startup
{
    public static string Connectionstring { get; private set; }
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        ...
        services.AddTransient<IDbConnection>((sp) => new NpgsqlConnection(this.Configuration.GetConnectionString("connection")));
        ...
    }
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        ...
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
            endpoints.MapRazorPages();
        });
        Connectionstring = Configuration["ConnectionStrings:connection"];
    }
}

 

Categories: ,

Related Article