Annotation Type ContextModule
-
public @interface ContextModule
Used to explicitly name a bean context and optionally specify if it depends on other bean contexts.If this annotation is not present then the name will be derived as the "top level package name" e.g. "org.example.featuretoggle"
Typically there is a single bean context per Jar (module). In that sense the name is the "module name" and the dependsOn specifies the names of modules that this depends on (provide beans that are used to wire this module).
This annotation is typically placed on a top level interface or package-info in the module.
package org.example.featuretoggle; import io.dinject.ContextModule; @ContextModule(name = "feature-toggle") public interface FeatureToggle { boolean isEnabled(String key); }dependsOn
We specify
dependsOnwhen we have a module that depends on beans that will be supplied by another module (jar).In the example below we have the "Job System" which depends on the common "Feature Toggle" module. When wiring the Job system module we expect some beans to be provided by the feature toggle module (jar).
package org.example.jobsystem; import io.dinject.ContextModule; @ContextModule(name = "job-system", dependsOn = {"feature-toggle"}) public interface JobSystem { ... }
-
-
-
provides
String[] provides
Additional module features that is provided by this module.These names are an addition to the module name and can be used in the
dependsOnof other modules.// A module that provides 'email-service' and also 'health-check'. // ie. it has bean(s) that implement a health check interface @ContextModule(name="email-service", provides={"health-checks"}) // provides beans that implement a health check interface // ... wires after 'email-service' @ContextModule(name="main", provides={"health-checks"}, dependsOn={"email-service"}) // wire this after all modules that provide 'health-checks' @ContextModule(name="health-check-service", dependsOn={"health-checks"})- Default:
- {}
-
-
-
dependsOn
String[] dependsOn
The list of modules this context depends on.Effectively dependsOn specifies the modules that must wire before this module.
// wire after a module that is called 'email-service' // ... or any module that provides 'email-service' @ContextModule(name="...", dependsOn={"email-service"})- Default:
- {}
-
-