Skip to content

3.2.0

Latest

Choose a tag to compare

@RomanQed RomanQed released this 12 Sep 23:22

amaya-di 3.2.0

Minor release focused on resource lifecycle support, scoped DI ergonomics, and small perf wins. No breaking changes to the 3.1.x API surface.

Added

  • DI-safe Closeable (non-throwing) in di-core.

    • Closeable#close() never throws; intended for best-effort cleanup.
    • Closeable.of(AutoCloseable) adapter to safely wrap existing AutoCloseable.
  • Closeable-aware factories

    • CloseableObjectFactory (extends ObjectFactory, Closeable).
    • LazyCloseableObjectFactory — thread-safe lazy init + idempotent close of produced value and the delegate.
  • Repository helpers

    • TypeRepository#putCloseable(Type, Closeable) and TypeRepository#putCloseable(Closeable) to register closeable singletons with proper teardown.
  • Scoped repository API

    • ScopedRepository with local-only lookups/iteration: getLocal, canProvideLocal, forEachLocal(...), localIterator, localFactoryIterator, etc.
    • ScopedTypeRepository implementation that overlays a parent repository with a local scope.
  • Builder split & configurer

    • New ServiceProviderConfigurer / ScopedProviderConfigurer extracted; ServiceProviderBuilder and ScopedProviderBuilder now extend these (no change to usage; enables reuse).
  • Scoped repository customization

    • withScopedRepository(Supplier<ScopedRepository>) on builders to plug custom scoped repo implementations.

Changed

  • Provider closing semantics

    • AbstractCloseableProvider and AbstractCloseableScopedProvider now close only values/factories that implement Closeable.
    • Calling ServiceProvider.close() does not tear down the DI container; it just invokes close() on registered Closeables in the (scoped) repository. The provider remains usable, but those resources are considered closed.
  • Lazy-by-default wrappers in builders

    • addSingleton(...) and addScopedSingleton(...) now auto-select a lazy wrapper:

      • If the implementation implements Closeable → uses LazyCloseableObjectFactory.
      • Otherwise → classic LazyObjectFactory.
    • No method overloads added; behavior is automatic.

  • Repository API polish

    • Introduced putCloseable* names to avoid shadowing and make intent explicit.

Performance

  • Internal cleanups and lazy path selection reduce overhead for wrapped scopes.
  • On our JMH suite (11u, same fixtures as 3.1.x), wrapped scope creation & creation+injection improved by ~8–13% depending on stub path (ASM/Reflect). Your mileage may vary.

Documentation

  • Comprehensive Javadoc across new/updated types:

    • Closeable, CloseableObjectFactory, LazyCloseableObjectFactory
    • ServiceProviderConfigurer, ScopedProviderConfigurer, ServiceProviderBuilder, ScopedProviderBuilder
    • ScopedRepository, ScopedTypeRepository, WrappedEntry
    • Clarified close semantics on providers (resources are closed; DI remains usable).

Tests

  • Expanded unit tests covering:

    • Closeable adapters and idempotent close.
    • Lazy closeable factory behavior (delegation, value close, delegate close).
    • Scoped repository local/global iteration and resolution rules.
    • Builders: lazy initialization paths, with* supplier usage, singleton wrapper selection, and closeable teardown wiring.
  • Overall higher coverage for builders and scope mechanics.

Migration notes

  • If you have resources that should be closed by the provider, implement io.github.amayaframework.di.core.Closeable or register instances via TypeRepository#putCloseable(...).
  • If you rely on AutoCloseable, wrap with Closeable.of(autoCloseable) or provide your own CloseableObjectFactory. (AutoCloseable is not invoked automatically.)