In my application I have a Service Manager that handles all my requests. Now this Service Manager uses external services in order to fulfill some particular kind of requests.
For example,consider below sample code:
Class ServiceManager{
private final A a;
private final B b;
private ExternalService externalService;
@Inject
public ServiceManager(A a, B b)
{
this.a =a;
this.b =b;
}
public void processIncomingRequestUsingExternalService(){...}
}
Now in order initialize ExternalService which approach is better using GUICE
- Use setter injection, as in future there might be 'n' number of different type of external service come into picture which this Service Manager might want to use.
- Or use constructor injection, as I have used for class A and B objects which are internal class of my application.
Note:- Here ExternalService is a Helper for External Service.
Aucun commentaire:
Enregistrer un commentaire