Package com.oorian.inject
Interface ServiceLocator
- All Known Implementing Classes:
ServiceRegistry
public interface ServiceLocator
Abstracts a dependency injection container for resolving services.
Implementations bridge Oorian to an external DI framework (Spring, CDI) or
use the built-in ServiceRegistry. The active locator is configured via
Services.setServiceLocator(ServiceLocator).
Built-in implementations:
ServiceRegistry— lightweight, Map-based service container
Custom implementations (external modules):
// Spring integration
public class SpringServiceLocator implements ServiceLocator {
private final ApplicationContext context;
public SpringServiceLocator(ApplicationContext context) {
this.context = context;
}
public <T> T get(Class<T> serviceClass) {
return context.getBean(serviceClass);
}
public <T> boolean has(Class<T> serviceClass) {
return context.getBeanNamesForType(serviceClass).length > 0;
}
}
- Since:
- 2.1
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Method Summary
-
Method Details
-
get
Resolves a service by its type.- Type Parameters:
T- the service type- Parameters:
serviceClass- the service class or interface- Returns:
- the service instance
- Throws:
ServiceNotFoundException- if no service is registered for the type
-
has
Checks whether a service is available for the given type.- Type Parameters:
T- the service type- Parameters:
serviceClass- the service class or interface- Returns:
trueif a service is registered for the type
-