First of all, in something like config.json you can add jura connect strings. Something like the following will work
"Data": { "BlogData": { "ConnectionString": "Server=tcp:YourHostname.net,1433;Database=YourDatabaseName;User ID=YourDBUser@YourDomain ;Password=YourPassword;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" }, "Identity": { "ConnectionString": "Server=tcp:YourHostname.net,1433;Database=YourDatabaseName;User ID=YourDBUser@YourDomain ;Password=YourPassword;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" } },
You have two DBC contexts. Say: YourApp.AppDBContext and YourApp.AppIdentityDBContext
Of course, you need to include them at the beginning of your CS file.
using YourApp.AppDBContext; using YourApp.AppIdentityDBContext;
In startup.cs, for example, in the startup method, your configuration builder would look like this:
var builder = new ConfigurationBuilder() .AddJsonFile("config.json") .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true); builder.AddEnvironmentVariables(); Configuration = builder.Build(); }
In the ConfigureServices method, you add your DBC texts as follows:
services.AddEntityFramework() .AddSqlServer() .AddDbContext<AppDbContext>(options => options.UseSqlServer(Configuration["Data:BlogData:ConnectionString"])) .AddDbContext<AppIdentityDbContext>(options => options.UseSqlServer(Configuration["Data:Identity:ConnectionString"]));
Hope this helps. Feel free to scream if I can expand this further.
source share