Reputation: 11782
I need to be able to configure my connection string at run time, preferably from a config file would be the simplest solution. However, I can't use ConnectionString.FromAppSetting nor ConnectionString.FromConnectionStringWithKey. My data-access assembly is referenced from console apps, win forms, and web. And while I can add "Settings" to my project, it's only a dll and won't bring that app.config over with it to the actual applications build destination.
I don't expect this is too uncommon. What is typically the way this is handled? Is this a prime example of when to use dependency injection (one that I could configure from a separate file?) I'm feeding the connection string to my 'unit of work' object, but I'd like to do it statically as to build the config and sessionfactory only once.
I can definitely clarify if needed, but I'm not sure the best way to ask.
Upvotes: 0
Views: 965
Reputation: 14156
You can use hibernate.cfg.xml (it works on every plattaform). Alternatively you can do the following
You can use ServiceLocation inside your DriverConnectionProvider or you can use the EnhancedBytecodeProvider on unhaddins. Search Enhanced bytecodeprovider and Fabio Maulo on google.
Here is an example: Dynamically change user info in connection string
Upvotes: 2