Announcement Announcement Module
Collapse
No announcement yet.
Bean design question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean design question

    I like to design my domain model without thinking about the database. That way I can unit test and pretty much run the entire system easily. However, I ran into a design decision where I have a few choices, but I'm not sure what the best practice is.

    I have a singleton bean called Administrator in the application context, which needs some references to things in the database. I don't really want to pass in references to DAOs to aquire them though, so using init() is out of the question. What would be the best spring construct to populate the Administrator object without it knowing about the DAOs? A builder object also in the application context?

    I'm also noticing that I'm going to have some problems keeping state too. For example, if a reference is changed in the database, the administrator object should be refreshed.

  • #2
    Re: Bean design question

    Originally posted by egervari
    I have a singleton bean called Administrator in the application context, which needs some references to things in the database. I don't really want to pass in references to DAOs to aquire them though, so using init() is out of the question. What would be the best spring construct to populate the Administrator object without it knowing about the DAOs? A builder object also in the application context?
    Let's say Administrator needs a reference to ThingyInDB. One approach is to create a ThingyInDBFactoryBean that knows how to produce an ThingyInDB instance from DB (being injected with a DataSource). Then in the Administrator definition simply inject a reference to a "thingyInDB" bean, whose class is set to ThingyInDBFactoryBean.

    Originally posted by egervari
    I'm also noticing that I'm going to have some problems keeping state too. For example, if a reference is changed in the database, the administrator object should be refreshed.
    This is more complex. There is another ongoing thread discussing leveraging JMX to achieve this. You might want to check it out.

    Comment

    Working...
    X