• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dependency injection for database server

 
Jacob Bridge
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I want to use dependency injection pattern in my assignment. So that my Data class wild contain such constructor



during startup of the application all dependencies wold be injected, like this:



and finally my DataAccessObjectImpl (please, notice that it's constructor would be private):



As you can see only one DAO instance would be created for one db file.
(I also plain to add ShutdownHook (Runtime.getRuntime().addShutdownHook(...)) during startup on order to close RandomAccessFile during shutdown, and it will use the same getInstance(..) method of DataAccessObjectImpl to receive appropriate DAO instance)

And here are my questions to you:

- What do you think about using dependencies injection in current situation? Do you think that Sun assessors will accept such solution (I afraid because in this case I don't have defult constructor in Data class)?
- Do you think it's good Idea to use getInstance() method in DAO, or it's better to instantiate DAO directly in the Data class constructor?
- Do you think that provided solution is too complicated and would cause frustrations to junior java developer?

I would be happy to know your opinion about this solution and your comment are highly appreciated!
Thank you in advance!
 
mohamed sulibi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jacob Bridge;

i think you implementation is very good from my opinion; also you can create a default and implements assessor for dao lockManager.

best regards.
Mohamed Sulibi
 
Jacob Bridge
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Mohamed Sulibi,

thank you for the answer and your opinion.

I agree with you, and in real life I would also create assessor methods instead of constructor args (in real life I actully would use springframework to inject all my dependencies). But I don't want to create defaults, at least for dao, mostly because in this case my Data class will need to know the location of database file in order to get instance of DAO object. But for LockManager it's ok, I think.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic