Reinhard is correct.
Your example is using Guice as a Service locator pattern rather than
Dependency Injection. See:
http://stackoverflow.com/questions/1557781/whats-the-difference-between-the-dependency-injection-and-service-locator-patte
Either Inject the DAOs (doing this via the constructor is my favourite as I
can mark the Instance variables as final) :
public class PersonService {
private final PersonDao personDao;
private final AddressDao addressDao;
@Inject
public PersonService (PersonDao personDao, AddressDao addressDao){
this.personDao = personDao;
this.addressDao = addressDao;
}
}
You may also wish to inject providers (e.g. Provider<PersonDao>) if you
want to defer instantiation of the DAOs until needed (e.g. the savePerson
method). But to be honest, since PersonDao is a singleton, you may as well
just keep it in the class and reuse it as required.
Dave Elton
On 19 October 2012 07:44, Reinhard Nägele <[email protected]>wrote:
> Why do you use the injector directly in your examples? This defeats the
> whole point of DI. You should inject the DAOs instead.
>
>
> Am Donnerstag, 18. Oktober 2012 20:12:28 UTC+2 schrieb पांडुरंग पाटिल:
>
>> I was also facing few issues while using Multiple Persistent units and
>> was able to get it working. refer this http://blog.**
>> pandurangpatil.com/2012/10/**mulitple-persistence-unit-**with-guice.html<http://blog.pandurangpatil.com/2012/10/mulitple-persistence-unit-with-guice.html>
>>
>>
>> Thanks,
>> -Pandurang.
>>
>> On Thursday, 17 May 2012 06:05:42 UTC+5:30, Michael Newton wrote:
>>>
>>> I just filed an issue for this - http://code.google.com/p/**
>>>> google-guice/issues/detail?id=**705<http://code.google.com/p/google-guice/issues/detail?id=705>
>>>
>>> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-guice/-/Wc9zuuu3cKYJ.
>
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.