Environmental variable and wirebox singletons

I currently have control, service and DAO layers within my model structure.

I have a specific environmental variable called DSN(data source) which is used a lot throughout my application (There may be more of these variables in the future)

I began by storing this value in the application scope… However our application functionality has changed since inception and the DSN can now change during a users login.

In addition I am planning to build test harnesses for my system which would allow testing my system over different scenarios in which this variable would change.

So the variable has become mutable.

One option would have been to set the variable on my DAO objects instantiation. But I also implement Wirebox dependancy management and for performance reasons would like as much of my model as possible to be singletons so this is not an option.

My final solution (which will require a lot of re-factoring) is to pass the DSN through from all of the layers… so a default DSN value can be overridden on any method call…(each method will have a DSN argument which defaults to the application value)

Obviously I would like to avoid this additional work… but I cannot think of any other way around it… Hope explanation is sufficiently clear and any help would be greatly appreciated.

Thanks for taking a look.

Alex

Passing something like a DSN through multiple layers of the application is the last option I’d choose. I’d be inclined to inject a service into your DAOs that is capable of determining the correct DSN.