I'm trying to understand the technical approach for implementing DI.
this code sample is DI taken from https://en.wikipedia.org/wiki/Dependency_injection- the injector is the c'tor:
// Constructor
Client(Service service, Service otherService) {
if (service == null) {
throw new InvalidParameterException("service must not be null");
}
if (otherService == null) {
throw new InvalidParameterException("otherService must not be null");
}
// Save the service references inside this client
this.service = service;
this.otherService = otherService;
}
Now, 2 DI principles:
- Thanks to the
Service
interface the client doesn't care who's the concrete service. - The client need to know the concrete service API.
My question: What is the technical way in which the client get to know the API of the injected service?
Aucun commentaire:
Enregistrer un commentaire