The IoC Container of Swiz is the BeanLoader class. Any beans defined in a registered BeanLoader can be injected into other beans or into views added to the display list.
Defining an injection target is done using the Autowire metadata tag. Common injection scenarios include the following:
- Inject Model into View
- Inject Model into Controller
- Inject Delegate into Controller
- Inject Service into Delegate
Autowire by type
If you define exactly one bean of a given type you can inject it into a matching destination with a plain [Autowire] tag. Note this works even if the bean is a concrete implementation of the interface to which the target is typed.
Autowire by id
If you have more than one bean of a given type defined, or if you simply prefer to be more explicit, you can request that a bean with a specific id be injected. This bean name/id must match the id attribute of the bean tag as defined in your BeanLoader.
Autowire property
Swiz can also inject public bean properties, rather than the beans themselves.
Two-way binding
By default, Swiz binds the injection target to the injection source (the bean or bean property). You can set up a reverse binding, so the source will receive updates made to the target, by setting the twoWay attribute of the [Autowire] tag to true.
{ 1 } Comments
It might sound obvious but, “public” attribute visibility seems to be mandatory. I’ve spend few minutes on trying to make my app work with “private” declaration.