Overview
Components play an important role in the extensibility of LoopBack 4. AComponent makes it easy for independent developers to contribute additionalfeatures to LoopBack. Components serve as a vehicle to group extensioncontributions such as Context Bindings and various artifacts toallow easier extensibility of your Application.
A typical LoopBack component is an npm packageexporting a Component class which can be added to your application.
Apart from its own properties, Component
class can have the followingproperties:
controllers
- An array of controller classes.providers
- A map of providers to be bound to the applicationcontext.classes
- A map of TypeScipt classes to be bound to the application context.servers
- A map of name/class pairs for servers.lifeCycleObservers
- An array of life cycle observers.bindings
- An array of bindings to be aded to the applicationcontext. A good example of using bindings to extend the functionality of aLoopBack 4 app iscontributing an additional body parser.These properties contribute to the application to add additional features andcapabilities.
LoopBack 4 was built with extensibility in mind and this includes Components,which can be allowed to contribute additional artifacts by adding a Mixin toyour Application class. This doesn’t change how a Component is registered(app.component()
) but it enables the Component to contribute additionalartifacts. For example:
- Repositories can be contributed by a Component by adding
RepositoryMixin
from@loopback/repository
to your Application - Booters can be contributed by a Componentby adding
BootMixin
from@loopback/boot
to your Application
Note:
Always check a component’s instructions to see if it requires the useof a Mixin. A Mixin may automatically register a Component, saving you thetrouble of having to do so manually. Again it’s best to check the documentationfor the given Component/Mixin.
See Using components andCreating components for more information.