I have a project class (Nuget Package). I need to read in a static class without constructor my connections string to MongoDB.
Static Class Method:
None of the above answers worked for me. I am building a .net core 2.1 api.
I used
public class Startup
{
public static string ConnectionString {get; private set;}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
ConnectionString = Configuration.GetConnectionString("xxxxxx");
app.UseMvc();
}
Then whenever i need it i call string ConnString = Startup.ConnectionString;