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) indi-core.Closeable#close()never throws; intended for best-effort cleanup.Closeable.of(AutoCloseable)adapter to safely wrap existingAutoCloseable.
-
Closeable-aware factories
CloseableObjectFactory(extendsObjectFactory,Closeable).LazyCloseableObjectFactory— thread-safe lazy init + idempotent close of produced value and the delegate.
-
Repository helpers
TypeRepository#putCloseable(Type, Closeable)andTypeRepository#putCloseable(Closeable)to register closeable singletons with proper teardown.
-
Scoped repository API
ScopedRepositorywith local-only lookups/iteration:getLocal,canProvideLocal,forEachLocal(...),localIterator,localFactoryIterator, etc.ScopedTypeRepositoryimplementation that overlays a parent repository with a local scope.
-
Builder split & configurer
- New
ServiceProviderConfigurer/ScopedProviderConfigurerextracted;ServiceProviderBuilderandScopedProviderBuildernow extend these (no change to usage; enables reuse).
- New
-
Scoped repository customization
withScopedRepository(Supplier<ScopedRepository>)on builders to plug custom scoped repo implementations.
Changed
-
Provider closing semantics
AbstractCloseableProviderandAbstractCloseableScopedProvidernow close only values/factories that implementCloseable.- Calling
ServiceProvider.close()does not tear down the DI container; it just invokesclose()on registeredCloseables in the (scoped) repository. The provider remains usable, but those resources are considered closed.
-
Lazy-by-default wrappers in builders
-
addSingleton(...)andaddScopedSingleton(...)now auto-select a lazy wrapper:- If the implementation implements
Closeable→ usesLazyCloseableObjectFactory. - Otherwise → classic
LazyObjectFactory.
- If the implementation implements
-
No method overloads added; behavior is automatic.
-
-
Repository API polish
- Introduced
putCloseable*names to avoid shadowing and make intent explicit.
- Introduced
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,LazyCloseableObjectFactoryServiceProviderConfigurer,ScopedProviderConfigurer,ServiceProviderBuilder,ScopedProviderBuilderScopedRepository,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.Closeableor register instances viaTypeRepository#putCloseable(...). - If you rely on
AutoCloseable, wrap withCloseable.of(autoCloseable)or provide your ownCloseableObjectFactory. (AutoCloseableis not invoked automatically.)