Results 1 to 2 of 2

Thread: Dependency Injection of connection depend. on session state

  1. #1
    Join Date
    Aug 2005
    Posts
    3

    Default Dependency Injection of connection depend. on session state

    We have (perhaps?) an unusual problem at work where we're currently trying to work out now that we've decided to rebuild our web application using Spring.

    In our design we have one master database and one database for each customer. This design can not be changed (and we don't want to either). Obviously, the master database can be configured in Spring and injected to any class needing it since its configuration parameters are static.

    However, the clients' databases are not. Sure, their databases all happen to reside on the same server, but the actual database names differ.

    When a user logs in, we associate with the user's session an object called SecureSession containing among other things information about user including which client he/she belongs to. Using the information in this SecureSession, we open the connection when needed to the client's database in our current design.

    This client connection, is it possible to somehow have it automatically dependency injected to any classes needing it?

    We have a number of DAO-objects which we use to talk to the database(s). A DAO-object will need to speak to both the master database and the client database for the user which made the current request.

    Ideally, I see the solution looking something like this.

    => User makes a request
    => If not logged in, send to login page, otherwise continue
    => Request is dispatched to appropiate controller
    => Controllers are configured to have DAOs dependency injected into them.
    => The DAOs have been given the master connection by Spring
    => Using the information in the request's SecureSession, the DAO's are also given a connection to the client's database

    So when methods are called in the DAO, you don't have to worry about where the two connections came from, they're just there.

    Is it possible to solve the last step above in an elegant manner with Spring? I'm hoping that their perhaps is some kind of interface once can implement and then configure to make the request dependent connection association.

    Anyone have any tips? Possible work-arounds?

    Thanks in advance.

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Last edited by robyn; May 15th, 2006 at 05:44 PM.

Similar Threads

  1. Hibernate Long Session Per Flow?
    By akw in forum Web Flow
    Replies: 21
    Last Post: Dec 12th, 2005, 08:06 PM
  2. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  3. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  4. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM
  5. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •