Trace: • Object Injection
Occasionally, it's important to add external objects in your running application without additional coding. We have an injection mechanism which is pretty simple. It's possible to inject custom Java objects or objects which implements the interface IInjectObject. The difference is that simple objects don't use an init method:
public interface IInjectObject { public String getDefaultName(); public void init(ISession pSession); }
To inject the object, simply put the configuration in config.xml:
The injection is
<?xml version="1.0" encoding="UTF-8"?> <application> ... <!-- inject in every LCO --> <inject class="com.package.app.MyClass" name="myClass"/> <!-- inject in specific LCO --> <inject ...> <allow instanceof="com.sibvisions.rad.server.MasterSession"/> <allow lifecyclename="com.package.app.screen.User"/> </inject> </application>
It's also possible to inject by ServiceLoader. Simply create a file with the name com.sibvisions.rad.server.IInjectObject in META-INF/services, in your classpath. The file should contain one line per object:
com.package.app.MyInjectObject
Be sure that MyInjectObject implements IInjectObject.