The Infusion Framework is designed to support highly flexible aggregation of reusable components. The Inversion of Control (IoC) system provides the ability for reusable components to pull dependencies from the environment rather than having to push them in initialisers. Inverting control this way allows users of the framework and components to customize implementations by plugging in alternative subcomponents, without having to modify the parent component code.
Compare the following examples:
fluid.initSubcomponent() with the specific parameters that the subcomponent implementation requires (the array of parameters is the third argument to
fluid.initSubcomponent()). The second argument to
fluid.initSubcomponent() is the string name of the subcomponent, as specified in the defaults (not necessarily the actual function name).
() call declares the default function to use for the subcomponents, by name. Users can override these defaults by specifying a different function name, but the arguments to the customized replacement must be the same, or the user will have to modify the code that calls
fluid.initSubcomponent() for that subcomponent. Note that this style of fluid.defaults call without gradeNames is no longer supported.
components section of the defaults provided to
fluid.defaults() will be initialized automatically when the component is constructed. In the component defaults, the types of components to use for the subcomponents are defined inside a property called
components. The values for the
type properties will be grade names. With the
autoInit grade directive, the component creator function will be generated from component defaults. Any code present in the old style creator function can then be distributed into appropriate IoC definitions. Most can be written declaratively, some still require to be registered as a listener to the standard component event