So I have a .net Core Web Api project and my DBAccess class library included in my solution as a separate project.
inside appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Password=L3tters&#s;Persist Security Info=True;User ID=Some_User;Initial Catalog=My_Cat;Data Source=Mt.Shasta"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
In startup.cs I have this:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.Configure<IISOptions>(options =>
{
});
services.AddSingleton<IConfiguration>(Configuration);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseMvc();
}
So, in controllers I can do stuff like this:
private readonly string _connectionString;
public FloorController(IConfiguration configuration)
{
_connectionString = configuration.GetConnectionString("DefaultConnection");
}
_connectionString = configuration.GetConnectionString("DefaultConnection");
All those goodies are in SNC_GSS:
But I need to get at the settings from DBAccess... I'd like to create a reference to SNC_GSS but I can't because SNC_GSS already has a reference to DBAccess and it'd create a circular ref...
Thoughts?