本文主要是介绍Pico 5 minutes Introdution Abstract,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
PicoContainer最重要的特征是能够实例化任何对象
盛入Class,即可返回实例对象
在大量具有复杂依赖关系的接口和对象的情况下,picoContainer显得非常有用。
PicoContainer identifies dependencies by looking at the constructors of registered classes (Constructor Injection). PicoContainer can also be though of as a generic factory that can be configured dynamically. PicoContainer is able to instantiate a complex graph of several interdependent objects.
PicoContainer provides a powerful alternative to the Singleton antipattern. With container hierarchies you can create singleton-like objects where you have fine grained control over the visibility scope of the instance. (The singleton pattern is static and global - it won't allow more than one instance, and it is visible from anywhere. Not nice).
A container (and its registered components) can get access to components registered in a parent container, but not vice-versa.
PicoContainer has support for Lifecycle. If your classes implement Startable, you can control the lifecycle of all your objects with a simple method call on the container. The container will figure out the correct order of invocation of start()/stop() all the objects managed by the container.
Calling start() on the container will call start() on all container managed objects in the order of their instantiation. This means starting with the ones that have no dependencies, and ending with the ones that have dependencies on others:
Lifecycle also works for hierarchies of containers. Calling start() on a container with child containers will start all the containers in a breadth-first order, starting with itself. Likewise, calling stop() will call stop() on all containers in the hierarchy in a depth-first order. The pictures below show what happens when start() and stop() are called on a container with children.
Lifecycle also works for hierarchies of containers. Calling start() on a container with child containers will start all the containers in a breadth-first order, starting with itself. Likewise, calling stop() will call stop() on all containers in the hierarchy in a depth-first order.
In order for hierarchy-aware lifecycle to work, child containers must be registered as components in their parent container. Just creating a container with another one as a parent will not cause the parent container to know about the child container.
Propagating Dependency
这篇关于Pico 5 minutes Introdution Abstract的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!