Nutz-Ioc Manual

Ioc - Composite loader


Use composite loader

Principle: it itself does not do anything, it just calls the other loader:

ComboIocLoader loader = new ComboIocLoader("*js",
                                               "ioc/dao.js",
                                               "ioc/service.js",
                                               "*anno",
                                               "com.myapp.module",
                                               "com.myapp.service",
                                               "*tx",
                                               // @Async注解,异步执行.
                                               "*async");

As in the example above, a combination of the loader, a combination Ioc loader 3, is a JsonLoader , is a AnnotationIocLoader , a transaction is AOP TransIocLoader (1.b.52 new), an asynchronous annotation loader.

ComboIocLoader constructor is a string deformation parameter set, all parameters, if an asterisk " * " at the beginning, is considered a type loader, behind the arguments as argument to the constructor of the loader until the next an asterisk " * " at the beginning of the parameter.

The above example, in fact, for the preparation of both Ioc container loader, loader JSON first is that the two dao.js and service.js profile reads configuration information container object . And the other Annotation loader from scans packages  com.myapp.module  and  com.myapp.service  child package has been under, and if found to have a container object (declared @IocBean notes, details  Ioc - Annotation loader ) it will load.

And the priority of these two loaders

The top surface of the front loader higher priority ,

In the example of this section, a higher priority than JsonLoader loader AnnotationIocLoader. That is, if two loaders are loaded named object, the subject places JsonLoader.


Usage of Mvc

In the Nutz.Mvc, Ioc container is provided IocProvider interface, so that each of the loader by a similar IocProvier achieved. For example ComboIocLoader, we will have a ComboIocProvider.

However, please do pay attention:  For ComboIocProvider:

It is a combination of still other IocLoader

Instead of

Other IocProvider

The following give an example:

@IocBy(type = ComboIocProvider.class,
       args = {"*js",
               "ioc/dao.js", 
               "ioc/service.js", 
               "*anno", 
               "com.myapp.module",
               "com.myapp.service"
        })
public class MainModule {
    ...

Now what can you compound?

  • XmlIocLoader
  • JsonLoader
  • AnnotationIocLoader
  • MapLoader
  • TransIocLoader
  • AsyncAopIocLoader
  • PropertiesIocLoader
  • Class that implements the interface of all IocLoader

Abbreviated class name

js         --> org.nutz.ioc.loader.json.JsonLoader
json       --> org.nutz.ioc.loader.json.JsonLoader
xml        --> org.nutz.ioc.loader.xml.XmlIocLoader
annotation --> org.nutz.ioc.loader.annotation.AnnotationIocLoader
anno       --> org.nutz.ioc.loader.annotation.AnnotationIocLoader
tx         --> org.nutz.aop.interceptor.ioc.TransIocLoader  #无参数
trans      --> org.nutz.aop.interceptor.ioc.TransIocLoader  #无参数
async       --> org.nutz.aop.interceptor.async.AsyncAopIocLoader #可以带一个线程池大小的参数
props       --> org.nutz.ioc.loader.properties.PropertiesIocLoader # 通过properties文件定义ioc bean
properties --> org.nutz.ioc.loader.properties.PropertiesIocLoader

Quote: http://nutzam.com/core/ioc/loader_combo.html 

Published 25 original articles · won praise 6 · views 7547

Guess you like

Origin blog.csdn.net/B_G_boy/article/details/103361866