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(componentCtor: Constructor<Component>, name?: string): Binding<Component>;

Parameters

Parameter Type Description
componentCtor Constructor<Component> The component class to add.
name string Optional component name, default to the class name

Returns:

Binding<Component>

Example


export class ProductComponent {
  controllers = [ProductController];
  repositories = [ProductRepo, UserRepo];
  providers = {
    [AUTHENTICATION_STRATEGY]: AuthStrategy,
    [AUTHORIZATION_ROLE]: Role,
  };
};

app.component(ProductComponent);