All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.dinject.ContextModule Maven / Gradle / Ivy

There is a newer version: 2.3
Show newest version
package io.dinject;

/**
 * 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. *

* *
{@code
 *
 * package org.example.featuretoggle;
 *
 * import io.dinject.ContextModule;
 *
 * @ContextModule(name = "feature-toggle")
 * public interface FeatureToggle {
 *
 *   boolean isEnabled(String key);
 * }
 *
 * }
* *

dependsOn

*

* We specify dependsOn when 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). *

* *
{@code
 *
 * package org.example.jobsystem;
 *
 * import io.dinject.ContextModule;
 *
 * @ContextModule(name = "job-system", dependsOn = {"feature-toggle"})
 * public interface JobSystem {
 *
 *   ...
 * }
 *
 * }
*/ public @interface ContextModule { /** * The name of this context/module. *

* Other modules can then depend on this name and when they do they should wire after than module. *

*/ String name() default ""; /** * Additional module features that is provided by this module. *

* These names are an addition to the module name and can be used in the dependsOn of other modules. *

* *
{@code
   *
   * // 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"})
   *
   * }
*/ String[] provides() default {}; /** * The list of modules this context depends on. *

* Effectively dependsOn specifies the modules that must wire before this module. *

*
{@code
   *
   * // wire after a module that is called 'email-service'
   * // ... or any module that provides 'email-service'
   *
   * @ContextModule(name="...", dependsOn={"email-service"})
   *
   * }
*/ String[] dependsOn() default {}; }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy