My structure of database (domain, data and services) are the same as : This application (MyFinance on CodePlex)
The problem is, that i have 2 database contexts (1 MyMasterContext) and 1 MySlaveContext.
And suppose that MySlaveContext can always be a different database / providerName / server.
(I know Entity Framework only supports MS SQL Server in EF 4.1)
MyMasterContext ALWAYS stays the same, this is where all the custom connectionstrings are saved.
So, my connectionstring can always change when i address the MySlaveContext, depending on which user is logged in.
In the current situation, MyMasterContext is always being auto-generated when it’s used, so is the MySlaveContext.
Now i have to add “dynamic connectionstring” support, the only problem is, that i don’t know where to add this functionality…
I have already implemented the ConnectionString in my UserIdentity (UserData), so it is always available when doing:
DirectCast(User.Identity,MyCustomUserIdentity).ConnectionString
Same with the ProviderName.
Also, my DataBaseFactory and UnitOfWork are “duplicated”, because i have one for the Master and one for the Slave (just to be sure).
Could someone help me how to add the “ConnectionString-detection” support?
I thought i could add it as a PropertyInjection or ParameterInjection in Unity, but i don’t have enough experience in this field to know it’s right or how to do it 🙂
Thanks in advance for anyone who could bring me on the right track 🙂
Fixed it myself by using an InjuctionConstructor..
In global.asax
It’s a parameter that can be supplied to a method. In this case, i’m updating my ConnectionString.