Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

So far, we haven't touched on Services at all. In fact, Services services aren't really needed to understand the concepts behind Contexts. However, their implementation can't be understood without them. Services solve a problem that arises in the above description: Tang's Configuration and Injector are monotonic. That is, information can only be added, never removed or overwritten. Now consider the case of the Context ID, which is kept in a Context's configuration and therefore its Injector. Forking that Injector with another context Configuration would result in a violation of Tang's monotonicity axiom, as that second context Configuration contains a binding to the same named parameter. This is where ServiceConfiguration comes into play: The ServiceConfiguration carries all the configuration data that shall be shared with contexts started on the current one. The ContextConfiguration contains all the information local to the context. We arrive at the following picture:

 

Task TaskInjector
Context BServiceInjector BContextInjector B
Context AServiceInjector AContextInjector A
RootContextRootServiceInjectorRootContextInjector

 

The various injector are formed like this:

Code Block
languagejava
Injector rootServiceInjector = new Injector(rootServiceConfiguration);
Injector rootContextInjector = rootServiceInjector.fork(rootContextConfiguration);

Injector serviceInjectorA    = rootServiceInjector.fork(serviceConfigurationA);
Injector contextInjectorA    = serviceInjectorA.fork(contextConfigurationA);

Injector serviceInjectorB    = serviceInjectorA.fork(serviceConfigurationB);
Injector contextInjectorB    = serviceInjectorB.fork(contextConfigurationB);

Injector taskInjector        = contextInjectorA.fork(taskConfiguration)

This ensures that only shareable information is passed to subsequent contexts and their injectors.