Yan blurs the familiar notion of dependency injection types because it enables unlimited varieties of dependency injection method.
Primitive types of Dependency Injection
For the simplest form of dependency injection — Constructor Injection, java pseudo code is like:
Corresponding Yan code using auto-wiring is:
For another most frequenly used dependency injection — Setter Injection, java pseudo code is like:
Corresponding Yan code with auto-wiring is:
The pseudo code "instantiate ..." could involve further dependency resolutions for the argument/property and their dependents. So we use pseudo code to hide the complexity.
For simplicity, in the rest of this article (and in most of Yan documents), we use "..." to denote the series of "instantiate XXX". Whenever you see an occurence of "...", some dependency resolution code has to be in place. Hence, a Component or ComponentAdapter in Pico's terminology is needed.
So, the constructor injection pseudo code becomes:
And the setter injection pseudo code becomes:
Dependency Injection in Yan vs. Pico
Next, we will compare some object creation logic in pseudo code and their corresponding way in Yan and Pico:
- Constructor Injection
- Pseudo Code:
- Yan:
- Pico:
- Pseudo Code:
- Setter Injection
- Pseudo Code:
- Yan:
- Pico:
- Pseudo Code:
- Generalized Setter Injection
By "generalized", we mean that Java Bean setters are invoked on an object not created by the default parameter-less constructor.- Pseudo Code:
- Yan:
- Pico: BeanPropertyComponentAdapter looks like it. But you lose container-managed properties by using it.
- Pseudo Code:
- Factory Injection
- Pseudo Code:
- Yan:
- Pico:
- Pseudo Code:
- Field Injection
- Pseudo Code:
- Yan:
- Pico: N/A
- Pseudo Code:
- Constructor then Factory
- Pseudo Code:
- Yan:
- Pico: N/A
- Pseudo Code:
- Factory inside Factory
- Pseudo Code:
- Yan:
- Pico: N/A
- Pseudo Code:
- Local Singleton
- Pseudo Code:
- Yan:
- Pico: N/A
- Pseudo Code:
- Array
- Pseudo Code:
- Yan:
- Pico: N/A
- Pseudo Code:
- Custom Collection
- Pseudo Code:
- Yan:
- Pico: N/A
- Pseudo Code:
- Dynamic Component
- Pseudo Code:
- Yan:
- Pico: N/A
- Pseudo Code:
As you can see, Pico and Yan both support the primitive constructor/setter/factory injection. Yan goes out of her way to support much more varieties of dependency injection logic.
In fact, Yan completely eliminates the restriction on dependency injection types. "type 1", "type 2", "type 3" blah blah blah, these injection types set forth by other IOC containers really don't stand out in Yan any more. They are nothing more than a few primitive injection methods among thousands of injection types enabled by Yan — if we still want to call them "types".
