Maybe this is not possible but I would like to validate.
I have a class and in its constructor it reads some value from the Windows Registry.
I need this valued to be readed inside the class, I could not pass it as a parameter to the class.
This is the class (a DBContext and the value readed is the Connection String)
public class VtulDb : IdentityDbContext<User>
{
public VtulDb()
{
RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
RegistryKey vtulRegistryBranch = hklm.OpenSubKey(@"SOFTWARE\Tulpep\Vtul");
string connectionString = vtulRegistryBranch.GetValue("DBConnectionString").ToString();
Database.Connection.ConnectionString = connectionString;
}
public DbSet<Computer> Computers { get; set; }
}
So, the issue is that this class is instanciated from a web site, in each request. So in each request the application is reading the registry key and I dont think this is the best approach.
What would you do to read this value from the Registry just the first time the class is instanciated, and then have the string in RAM?