powered by ASAP

What You Will Learn

In this short summary you will get an idea how to use the ContextBuilder to create the default IContext of the framework.

1. Basics

You can use the ContextBuilder to create the default IContext provided by the framework. The builder needs an IServiceProviderFactory to create the context.

2. The Context

The IContext resulting from the builder wraps the managed IServiceProvider in a „proxy provider“ enhancing its abilities by allowing to find services with the Java ServiceLoader mechanism. This mechanism is used as a fallback by default, but can be prioritized by the IServiceProvider.

The proxy provider also wraps any IPersistenceService registered, to be able to transform data from the persistence with the help of the IDataTransformer service.

3. Builder Constraints

  • The IServiceProvider instantiated by the factory needs to have the services IJsonMapper and IDataTransformer registered.

    • This constraint can also be fulfilled when the services are registered to the Java ServiceLoader. For example when having dependencies on the default implementations de.asap.pak.core:pak-default-datatransformer

4. Usage

The following method example should show you, how to use the ContextBuilder to create the default IContext of the framework.

public IContext buildContext(){
    final ContextBuilder cb = new ContextBuilder(); (1)
    cb.setServiceProviderFactory(new SimpleServiceProviderFactory()); (2)
    return cb.build(); (3)
1 Create the ContextBuilder with its empty constructor.
2 Set the mandatory IServiceProviderFactory. You need to make sure that the resulting IServiceProvider has the two needed services registered, or at least have dependencies on them, so that the ServiceLoader is able to find them.
3 The last step is to build the default context. Ready to be used by the EngineBuilder for example.