ServiceProvider

Service provider interface for dependency injection and service management in the Wow framework. Provides methods to register services by type and name, and retrieve them when needed. This interface supports both type-based and name-based service resolution.

Implementations should provide thread-safe operations for concurrent access.

Author

ahoo wang

Inheritors

Properties

Link copied to clipboard
abstract val serviceNames: Set<String>

Set of all registered service names. This provides a way to discover what services are available in the provider.

Functions

Link copied to clipboard
abstract fun copy(): ServiceProvider
Link copied to clipboard
abstract fun copyTo(target: ServiceProvider)

Copies all registered services from this provider to the target provider. This is useful for merging service providers or creating combined providers.

Link copied to clipboard

Retrieves a required service using reified type information, throwing an exception if not found. This is a convenience extension that automatically uses the reified type for lookup.

fun <S : Any> ServiceProvider.getRequiredService(serviceType: Class<S>): S

Retrieves a required service by Java class, throwing an exception if not found. This method guarantees that a service is returned or an exception is thrown.

Retrieves a required service by name, throwing an exception if not found. This method guarantees that a service is returned or an exception is thrown.

Retrieves a required service by Kotlin type, throwing an exception if not found. This method guarantees that a service is returned or an exception is thrown.

Link copied to clipboard
abstract fun <S : Any> getService(serviceName: String): S?

Retrieves a service by its registered name. Returns null if no service with the specified name is registered.

abstract fun <S : Any> getService(serviceType: KType): S?

Retrieves a service by its Kotlin type. Returns null if no service of the specified type is registered.

Link copied to clipboard
inline fun <S : Any> ServiceProvider.getService(): S?

Retrieves a service using reified type information. This is a convenience extension that automatically uses the reified type for lookup.

Link copied to clipboard
abstract fun register(service: Any, serviceName: String = service.javaClass.toName(), serviceType: KType = service.javaClass.kotlin.defaultType)

Registers a service instance with the provider. The service can be registered with a custom name and type, or use defaults derived from the service instance.

Link copied to clipboard
inline fun <S : Any> ServiceProvider.register(service: Any, serviceName: String = service.javaClass.toName())

Registers a service with reified type information. This is a convenience extension that automatically infers the service type using reified generics.