This framework is the implementation of a mix of the Service Locator Pattern and a
the Dependency Injection Pattern. These patterns are described by Martin Fowler in
this article. The BeanRepository
does not use reflection for injecting beans. Because of that fact, it can be used in
the Java sandbox, where reflection is not allowed.
- simple, self-explanatory and failsafe configuration in Java code
- no use of reflection or annotations
- constructor injection
- support for singletons, prototypes and instances
- provider
- factories
- aliases for beans
- fail fast on start up
- execute code after initialisation of the bean (post construct)
- configurable if singletons are lazy initialised or not
- detect beans of a specific type
- modularity possible
- cyclic references not supported directly. But if needed, see CyclicReferenceExampleApp for a solution
- no request or session scope
- no initialisation code allowed in constructor
- constructor may be called multiple times while working with the
BeanRepository
- constructor may be called multiple times while working with the
- a bean can only be accessed by a class
Include the following artifact to use the BeanRepository
:
<dependency>
<groupId>com.github.tinosteinort</groupId>
<artifactId>beanrepository</artifactId>
<version>1.7.0</version>
</dependency>
See SimpleExampleApp for ar very basic example.
See EventExampleApp for an example with events and listeners.
See CyclicReferenceExampleApp for an example with cyclic references.
Enhancements:
- Introduce
BeanRepositoryApplication
- Add examples
Fixes:
- Issue#4: onPostConstruct of singleton beans is executed if the bean is requested, not when the BeanRepository is build
- Issue#5: onPostConstruct of a Factory Bean is not triggered
Enhancements:
- Aliases for beans
Fixes:
- Issue#3: StackOverflowError when using PostConstructible in Combination with ConstructorInjection
Fixes:
- Issue#2: getProvidersForSingletons() does not consider Factories
Enhancements:
- Issue#1: Method should be private, not for external use
- Support simple Access to Prototype Beans with Parameter (with and without Dependencies to other Beans)
Fixes:
- Modularisation does not work as expected. Concept refactored.
Enhancements:
- Constructor Injection
Fixes:
Factory.createInstance()
is not called while dryRun. It is executed once for singleton Beans, and every time, when a prototype Bean is requested
Enhancements:
- A
Factory
can be used to create Beans
Enhancements:
- Add
Provider
Interface, and Methods to get Providers for registered Beans
Fixes:
onPostConstruct
was called multiple Times on referenced Beans
Enhancements:
- Add other
getBean(...)
Methods toBeanAccessor
. This allows to generateprototype
Beans in a Constructor
Initial Version