Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/avh4/picocontainer-example
How to use PicoContainer with dynamically-created dependencies
https://github.com/avh4/picocontainer-example
Last synced: 8 days ago
JSON representation
How to use PicoContainer with dynamically-created dependencies
- Host: GitHub
- URL: https://github.com/avh4/picocontainer-example
- Owner: avh4
- Created: 2013-08-10T19:45:19.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-08-10T21:07:30.000Z (over 11 years ago)
- Last Synced: 2024-10-27T12:06:14.927Z (about 2 months ago)
- Language: Java
- Size: 156 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## picocontainer-example
How to use [PicoContainer](http://picocontainer.codehaus.org/) with dynamically-created dependencies
[PicoContainer](http://picocontainer.codehaus.org/) is a [dependency-injection](http://www.martinfowler.com/articles/injection.html)
framework focused on simplicity. It emphasizes constructor injection and has a simple configuration mechanism that does not require
annotations, in contrast to the popular alternative, [Guice](https://code.google.com/p/google-guice/).One shortcoming of PicoContainer is that it does not provide clear documentation about how to approach writing code that needs to
dynamically create instances. In Guice, this would be accomplished by injecting a `Provider` of the type you needed to dynamically
instantiate.This project shows an example of a good pattern of doing this with PicoContainer. The solution used here is to explicitly create a provider
class with has a `PicoContainer` injected into it. If you follow this pattern, you should take care not to allow your non-provider classes to
inject the PicoContainer.This project also demonstrated the flexible and loosely-coupled architecture that results from refactoring code to use constructor injection
in place of the `new` operator. Notably `MainWindow` depends only on `ShowInfoWindowButton`: and as a result,
`ShowInfoWindowAction`, `InfoWindow`, and `InfoWindowProvider` are completely hidden from it.[Link to the relevant source folder](src/main/java/net/avh4/scratch/picocontainerexample)