API Reference
Complete public API surface of com.cristianllanos.container.
Core Interfaces
Registrar
Registration of bindings and service providers.
interface Registrar {
fun register(vararg providers: Any): Registrar
fun <T : Any> factory(type: Class<T>, factory: Container.() -> T): Registrar
fun <T : Any> singleton(type: Class<T>, factory: Container.() -> T): Registrar
fun <T : Any> scoped(type: Class<T>, factory: Container.() -> T): ScopedRegistration<T>
}Resolver
Resolution of dependencies from the container.
interface Resolver {
fun <T : Any> resolve(type: Class<T>): T
}Caller
Invocation of functions with auto-resolved parameters.
interface Caller {
fun <T> call(callable: KCallable<T>): T
}Container
Combines registration, resolution, and calling. Creates child scopes.
interface Container : Registrar, Resolver, Caller {
fun child(): Scope
}Scope
A child container with a closeable lifecycle.
interface Scope : Container, AutoCloseableAutoResolver
Strategy for resolving unregistered types. The default implementation uses reflection on primary constructors. Parameters with default values are skipped when their type cannot be resolved — Kotlin's default value is used instead.
interface AutoResolver {
fun <T : Any> resolve(type: Class<T>, resolver: Resolver): T
}Container Creation
// Basic constructor
fun Container(
autoResolver: AutoResolver = ReflectionAutoResolver()
): Container
// DSL builder
fun Container(
autoResolver: AutoResolver = ReflectionAutoResolver(),
init: Container.() -> Unit,
): ContainerExtension Functions
Registration (on Registrar)
// With factory lambda
inline fun <reified T : Any> Registrar.factory(noinline factory: Container.() -> T): Registrar
inline fun <reified T : Any> Registrar.singleton(noinline factory: Container.() -> T): Registrar
inline fun <reified T : Any> Registrar.scoped(noinline factory: Container.() -> T): ScopedRegistration<T>
// Auto-resolved (no lambda — resolves via primary constructor)
inline fun <reified T : Any> Registrar.factory(): Registrar
inline fun <reified T : Any> Registrar.singleton(): Registrar
inline fun <reified T : Any> Registrar.scoped(): ScopedRegistration<T>Resolution (on Resolver)
inline fun <reified T : Any> Resolver.resolve(): T
inline fun <reified T : Any> Resolver.resolveOrNull(): T? // null if unresolvable
inline fun <reified T : Any> Resolver.has(): Boolean // true if resolvable
inline fun <reified T : Any> Resolver.lazy(): Lazy<T> // deferred resolutionScoping (on Container)
// Block-based scope with automatic cleanup
inline fun <R> Container.scope(block: (Scope) -> R): R
// Scope with pre-registered providers
inline fun <R> Container.scope(vararg providers: Any, block: (Scope) -> R): RTypes
ScopedRegistration<T>
Returned by scoped() to allow attaching dispose hooks.
class ScopedRegistration<T : Any> {
fun onClose(action: (T) -> Unit): Registrar
}Exceptions
UnresolvableDependencyException
Thrown when a dependency cannot be resolved — typically a required primitive (String, Int, etc.) or an unregistered interface with no concrete fallback.
ScopeRequiredException
Thrown when a scoped binding is resolved from the root container instead of within a scope.