public class ApplicationContext extends AbstractContext
The application context is the context with the longest life time. For each
application there is exactly one application context. Because of thois the
context is designed as a singleton. You can access the context by using the
getInstance() method.
How to use a context
A context has a defined life time and can hold the data model of your
aplication or of a part of your application. To do so you can easily register
objects to your context:
DataModel model = ...
context.register(model);
In your controller:
DataModel model = context.getRegisteredObject(DataModel.class);
If you need more than one instance of a class in your context you can simple register the by using string based keys:
DataModel model1 = ...
DataModel model2 = ...
context.register("firstModel", model);
context.register("secondModel", model);
In your controller:
DataModel firstModel = context.getRegisteredObject("firstModel");
A context can simple used in a controller by injecting the context. DataFX provides annotations to inject all different context types:
"@FXMLApplicationContext"
ApplicationContext myApplicationContext;
By doing so you can easily access all your data in your controller and share data between different controllers.
| ?????? | ????? |
|---|---|
static ApplicationContext |
getInstance()
Returns the single instance of the application context (singleton)
|
getId, getRegisteredObject, getRegisteredObject, register, register, register, toStringpublic static ApplicationContext getInstance()