Abnaxos / meldioc

A prototype of an IoC (Inversion of Control) library for Java
MIT License
5 stars 1 forks source link

Introduce fallback provisions & extension points #74

Open Abnaxos opened 4 years ago

Abnaxos commented 4 years ago

Many of the library features have two variants: one with a ShutdownFeature and one without. This is a common situation: if a feature is present, use it, otherwise don't. Another example could be JMX: register an MBean if we're using JMX, otherwise don't.

Most such situations could be solved by a no-op fallback provision declared in the feature, e.g.:

@Provision(fallback = true)
protected ShutdownController shutdownController() {
  return ShutdownController.NOOP;
}

The traits of fallback provisions are:

The same mechanism is usable for implementing optional extension points: provide a fallback noop extension point if none could be found.