Sharing an Oracle connection across multiple data handlers
I have a solution in which an UpdateController class manages the logic for updating data. This controller calls various classes for managing data (ClaimData, StatementData, etc.). What's the best way to share connection across these 开发者_运维问答data handlers--use a singleton, or create another class for managing the connection and passing it to each data handler? What if the application is multithreaded?
Thanks in advance.
you could use dependency injection to provide each of these with a connection...
another way is to use an Oracle provider with internal Connection pooling (for example Devart dotconnect, I am only a customer)... then you only share the connection string via dependency injection or configuration file... every class instantiates/releases the connection on its own... the central connection pooling takes care of the rest (reusing connections etc)... this way you don't have to worry about any threading issues regarding connections...
精彩评论