c# - Passing entity connection string dynamically - multiple entities with multiple environment -


i have multiple entities in project. customer don't want keep connection strings in web.config file. create environmental variable each entity in octopus , create environment config file in project. need read environment variables , pass entities.

i cannot use parametarized constructor requires lot of code change. cannot modify auto generated entity context files.

i tried partial class , parametarized constructor.

public partial class sitesentities     {         public sitesentities(string conn)             : base(getconnectionstring())         {          }          public static string getconnectionstring()         { //code } } 

this require code change while initializing each entity. challenging task since using @ lot of place

 using (sitesentities entities = new sitesentities()) { //code } 

can suggest alternate solution this?

dependency injection awesome solve this. think way mentioned should work, (it's ugly, tho):

public partial class sitesentities {     public sitesentities()         : base(getconnectionstring())     {     }      public static string getconnectionstring()     {         return environment.getenvironmentvariable("my_env_varible");     } } 

what did missunderstand if that's not working you?


Comments