dimanche 21 janvier 2018

How to inject multiple DAO in service layer manually

I'm writing web app with servlets only. I have service layer and I want to inject some DAO in this service. I'd like to pass then through service constructor. But I think it will be bad if in controller I will create service like this(It is dirty, I think):

UserService userService = new UserService(new UserDao(), new OtherDao());

What is the best way create instance of service and pass to it DAO? Maybe I should use Abstract Factory?

Thank you in advance!

Aucun commentaire:

Enregistrer un commentaire