-
Notifications
You must be signed in to change notification settings - Fork 16
10. Context
Inside a Nalu application the context is the store of all shared application information.
The context will be instantiated by the framework and can not be overriden or set by the developer implementation with another instance!
It is injected in every controller, filter, handler, module and loader. All controllers, handlers, filters, module and the loader will have access to the same instance.
This is a good place to store information that should be available application wide.
The context is a required attribute of the @Application
- and (in case of a multi module project) @Module
-annotation.
There are two different ways of implementing the context depending of the type of the Nalu application:
-
a single module implementation
-
a multi module implementation
Inside a single module implementation you can use any POJO you like. You only need to add the IsContext
-interface. The simplest implementation of a context looks like that:
public class MyApplicationContext
implements IsContext {
private String attribute;
public MyApplicationContext() {
}
public String getAttribute() {
return this.attribute;
}
public void setAttribute(String attribute) {
this.attirbute = attribute;
}
}
To inform Nalu about the context, you have to set the attribute context of the Application
-annotation:
@Application(loader = MyApplicationLoader.class,
startRoute = "/application/search",
context = MyApplicationContext.class)
interface MyApplication
extends IsApplication {
}
In case you plan to add modules in the future, you should consider the use of the AbstractModuleContext
-class.
See Multi Module Implementation for more information.
Inside a multi module implementation you need a different kind of the context. (See the Module wiki page for more information).