public <T> T getService(String serviceId, Class<T> serviceInterface)
{
assert InternalUtils.isNonBlank(serviceId);
assert serviceInterface != null;
ServiceDef3 def = getServiceDef(serviceId);
// RegistryImpl should already have checked that the service exists.
assert def != null;
Object service = findOrCreate(def, null);
try
{
return serviceInterface.cast(service);
}
catch (ClassCastException ex)
{
// This may be overkill: I don't know how this could happen
// given that the return type of the method determines
// the service interface.
throw new RuntimeException(IOCMessages.serviceWrongInterface(serviceId, def.getServiceInterface(),
serviceInterface));
}
}