Page Contents
Home > @loopback/core > Application > component
Application.component() method
Add a component to this application and register extensions such as controllers, providers, and servers from the component.
Signature:
component<T extends Component = Component>(componentCtor: Constructor<T>, nameOrOptions?: string | BindingFromClassOptions): Binding<T>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| componentCtor | [Constructor](/doc/en/lb4/apidocs.context.constructor.html)<T> | The component class to add. |
| nameOrOptions | string \| [BindingFromClassOptions](/doc/en/lb4/apidocs.context.bindingfromclassoptions.html) | _(Optional)_ Optional component name or options, default to the class name |
Returns:
Binding<T>
Example
export class ProductComponent {
controllers = [ProductController];
repositories = [ProductRepo, UserRepo];
providers = {
[AUTHENTICATION_STRATEGY]: AuthStrategy,
[AUTHORIZATION_ROLE]: Role,
};
};
app.component(ProductComponent);