public class DiPlugin
extends java.lang.Object
依赖注入插件
使用过 Spring 的一定知道 DI 和 IOC,这个插件功能类似,但是更加简易化操作,更方便
注意: 在使用这个插件之前必须保证 Tuz 已经初始化!
Dependency inject plugin
If you have used Spring framework, you must know DI and IOC
This plugin can do the same work as Spring do, but more easy
Notice: Init Tuz before using this plugin!
传统的方式使用接口: xxxService service = new xxxServiceImpl(); 这种方式并没有真正解耦,使用 Spring 这类框架可以达到解耦效果,但是需要引入大量框架 而使用 Tuz 可以轻松做到解耦,请看下面:
Tuz.load(new ClasspathPropertiesLoader("test.properties", "test"));
// 直接获取实现类,而不用注入实现类的细节
xxxService service = DiPlugin.useInstance("xxxService", "test", xxxService.class);
service.say("Hello, Tuz!");
同样的,你可以不指定命名空间,但是,真的不推荐!!! //Tuz.load(new ClasspathPropertiesLoader("test.properties")); //xxxService service = DiPlugin.useInstance("xxxService", xxxService.class); //service.say("Hello, Tuz!");
Email: fishinlove@163.com
created by 2019/03/29 12:50:46
| 构造器和说明 |
|---|
DiPlugin() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> T |
useInstance(java.lang.Class<T> classType)
得到类实例
这里会根据 classType 的 getSimpleName() 去获取 key,并且利用反射生成实例对象
注意这里的实例模式是根据 Tuz.getConfig().isSingleton() 中的设置来决定的
Get class instance
Use reflect to instance a new object with given classType's simpleName
Notice that the mode creates the instance depends on Tuz.getConfig().isSingleton()
|
static <T> T |
useInstance(java.lang.Class<T> classType,
boolean singleton)
得到类实例
这里会根据 classType 的 getSimpleName() 去获取 key,并且利用反射生成实例对象
Get class instance
Use reflect to instance a new object with given classType's simpleName
|
static <T> T |
useInstance(java.lang.String key,
java.lang.Class<T> classType)
得到类实例
这里会根据 key 值获取 value,并且利用反射生成实例对象
注意这里的实例模式是根据 Tuz.getConfig().isSingleton() 中的设置来决定的
Get class instance
Use reflect to instance a new object with given value of key
Notice that the mode creates the instance depends on Tuz.getConfig().isSingleton()
|
static <T> T |
useInstance(java.lang.String key,
java.lang.Class<T> classType,
boolean singleton)
得到类实例
这里会根据 key 值获取 value,并且利用反射生成实例对象
Get class instance
Use reflect to instance a new object with given value of key
|
static <T> T |
useInstance(java.lang.String key,
java.lang.String namespace,
java.lang.Class<T> classType)
得到类实例
这里会根据 key 值获取 value,并且利用反射生成实例对象
注意这里的实例模式是根据 Tuz.getConfig().isSingleton() 中的设置来决定的
Get class instance
Use reflect to instance a new object with given value of key
Notice that the mode creates the instance depends on Tuz.getConfig().isSingleton()
|
static <T> T |
useInstance(java.lang.String key,
java.lang.String namespace,
java.lang.Class<T> classType,
boolean singleton)
得到类实例
这里会根据 key 值获取 value,并且利用反射生成实例对象
Get class instance
Use reflect to instance a new object with given value of key
|
public static <T> T useInstance(java.lang.Class<T> classType,
boolean singleton)
得到类实例
这里会根据 classType 的 getSimpleName() 去获取 key,并且利用反射生成实例对象
Get class instance
Use reflect to instance a new object with given classType's simpleName
T - 实际类型
Real type
classType - 类对象的实际类类型
The real type of class instance
singleton - 是否以单例模式创建对象实例
Use singleton mode to create instance or not
返回得到的类实例
Return class instance
public static <T> T useInstance(java.lang.Class<T> classType)
得到类实例
这里会根据 classType 的 getSimpleName() 去获取 key,并且利用反射生成实例对象
注意这里的实例模式是根据 Tuz.getConfig().isSingleton() 中的设置来决定的
Get class instance
Use reflect to instance a new object with given classType's simpleName
Notice that the mode creates the instance depends on Tuz.getConfig().isSingleton()
T - 实际类型
Real type
classType - 类对象的实际类类型
The real type of class instance
返回得到的类实例
Return class instance
Tuz.getConfig(),
TuzConfig.isSingleton()public static <T> T useInstance(java.lang.String key,
java.lang.Class<T> classType,
boolean singleton)
得到类实例
这里会根据 key 值获取 value,并且利用反射生成实例对象
Get class instance
Use reflect to instance a new object with given value of key
T - 实际类型
Real type
key - 根据这个 key 找到类的全名
Find the class by this key
classType - 类对象的实际类类型
The real type of class instance
singleton - 是否以单例模式创建对象实例
Use singleton mode to create instance or not
返回得到的类实例
Return class instance
public static <T> T useInstance(java.lang.String key,
java.lang.Class<T> classType)
得到类实例
这里会根据 key 值获取 value,并且利用反射生成实例对象
注意这里的实例模式是根据 Tuz.getConfig().isSingleton() 中的设置来决定的
Get class instance
Use reflect to instance a new object with given value of key
Notice that the mode creates the instance depends on Tuz.getConfig().isSingleton()
T - 实际类型
Real type
key - 根据这个 key 找到类的全名
Find the class by this key
classType - 类对象的实际类类型
The real type of class instance
返回得到的类实例
Return class instance
public static <T> T useInstance(java.lang.String key,
java.lang.String namespace,
java.lang.Class<T> classType,
boolean singleton)
得到类实例
这里会根据 key 值获取 value,并且利用反射生成实例对象
Get class instance
Use reflect to instance a new object with given value of key
T - 实际类型
Real type
key - 根据这个 key 找到类的全名
Find the class by this key
namespace - 指定的命名空间,用于区分不同的资源文件
Appointed namespace to different resource
classType - 类对象的实际类类型
The real type of class instance
singleton - 是否以单例模式创建对象实例
Use singleton mode to create instance or not
返回得到的类实例
Return class instance
public static <T> T useInstance(java.lang.String key,
java.lang.String namespace,
java.lang.Class<T> classType)
得到类实例
这里会根据 key 值获取 value,并且利用反射生成实例对象
注意这里的实例模式是根据 Tuz.getConfig().isSingleton() 中的设置来决定的
Get class instance
Use reflect to instance a new object with given value of key
Notice that the mode creates the instance depends on Tuz.getConfig().isSingleton()
T - 实际类型
Real type
key - 根据这个 key 找到类的全名
Find the class by this key
namespace - 指定的命名空间,用于区分不同的资源文件
Appointed namespace to different resource
classType - 类对象的实际类类型
The real type of class instance
返回得到的类实例
Return class instance
Copyright © 2019. All Rights Reserved.