public interface InventoryService {
boolean checkInventory(Item item, int quantity);
void updateInventory(Item item, int quantity);
}
public class DatabaseInventoryService implements InventoryService {
// ...
}
public interface PaymentService {
boolean processPayment(Order order);
}
public class CreditCardPaymentService implements PaymentService {
// ...
}
public class OrderProcessor {
private final InventoryService inventoryService;
private final PaymentService paymentService;
@Inject
public OrderProcessor(InventoryService inventoryService, PaymentService paymentService) {
this.inventoryService = inventoryService;
this.paymentService = paymentService;
}
public void processOrder(Order order) {
// ...
}
}
<context-param>
<param-name>javax.inject.Injector</param-name>
<param-value>com.example.MyInjector</param-value>
</context-param>