SimpleServiceProvider

Simple implementation of ServiceProvider using thread-safe ConcurrentHashMap for storage. Provides basic service registration and retrieval functionality with support for both type-based and name-based lookups. Supports subtype matching for type-based lookups.

This implementation is suitable for most use cases requiring a lightweight, thread-safe service provider.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
open override val serviceNames: Set<String>

Set of all registered service names. Returns a view of the keys in the namedServices map.

Functions

Link copied to clipboard
open override fun copy(): SimpleServiceProvider

Creates a shallow copy of this service provider. The copy contains references to the same service instances but in separate maps.

Link copied to clipboard
open override fun copyTo(target: ServiceProvider)

Copies all registered services from this provider to the target provider. Iterates through all named services and registers them with the target provider.

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
open override fun <S : Any> getService(serviceName: String): S?

Retrieves a service by its registered name. Performs a direct lookup in the named services map.

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

Retrieves a service by its Kotlin type. First tries exact type match, then falls back to subtype matching if no exact match is found.

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
open override fun register(service: Any, serviceName: String, serviceType: KType)

Registers a service with the provider. Stores the service in both typed and named service maps for efficient lookup.

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.