I have my own framework that I've been working on for years. It has an AppSecurity
project that handles users, roles, permissions, etc. For it, I created an EF Core code-first DbContext
class:
internal class AppSecurityDataContext : DbContext
{
private string _connectionString = @"Server=mysite;Database=TheLastAppIWorkedOn;User Id=abc1;Password=xyx2;";
public AppSecurityDataContext()
{
}
public AppSecurityDataContext(string connectionString)
{
_connectionString = connectionString;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(_connectionString);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<UserEntity>().HasData
(
new UserEntity
{
// Properties set here
}
);
}
}
Right now I'm working on a WPF app called Falcon. It has its own DbContext which manages the Falcon DB objects. Right now, the connection string for it is stored in the DbContext class becuase I'm not sure how this is supposed to be done.
private string _connectionString = @"Server=mysite;Database=Falcon;User Id=someone;Password=somepwd;";
public FalconDataContext()
{
}
public FalconDataContext(string connectionString)
{
_connectionString = connectionString;
}
public FalconDataContext(DbContextOptions<FalconDataContext> options) :
base(options)
{
}
Next week, I could be in another app that needs to use AppSecurity
. Herein lies the problem - when I work on other apps that use the AppSecurity
project, I have to open its DbContext
class, change the connection string, then open Package Manager and rebuild.
So, how can my AppSecurity
project get the connection string the other project I'm working?