@loopback/docs
Version:
Documentation for LoopBack 4
53 lines (34 loc) • 1.3 kB
Markdown
lang: en
title: 'API docs: core.application.component'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
permalink: /doc/en/lb4/apidocs.core.application.component.html
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/core](./core.md) > [Application](./core.application.md) > [component](./core.application.component.md)
## Application.component() method
Add a component to this application and register extensions such as controllers, providers, and servers from the component.
<b>Signature:</b>
```typescript
component(componentCtor: Constructor<Component>, name?: string): Binding<Component>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| componentCtor | <code>Constructor<Component></code> | The component class to add. |
| name | <code>string</code> | Optional component name, default to the class name |
<b>Returns:</b>
`Binding<Component>`
## Example
```ts
export class ProductComponent {
controllers = [ProductController];
repositories = [ProductRepo, UserRepo];
providers = {
[AUTHENTICATION_STRATEGY]: AuthStrategy,
[AUTHORIZATION_ROLE]: Role,
};
};
app.component(ProductComponent);
```