---
lang: en
title: 'API docs: core.application.service'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
permalink: /doc/en/lb4/apidocs.core.application.service.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/core](./core.md) &gt; [Application](./core.application.md) &gt; [service](./core.application.service.md)

## Application.service() method

Add a service to this application.

<b>Signature:</b>

```typescript
service<S>(cls: Constructor<S> | Constructor<Provider<S>>, name?: string): Binding<S>;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  cls | <code>Constructor&lt;S&gt; &#124; Constructor&lt;Provider&lt;S&gt;&gt;</code> | The service or provider class |
|  name | <code>string</code> |  |

<b>Returns:</b>

`Binding<S>`

## Example


```ts
// Define a class to be bound via ctx.toClass()
@bind({scope: BindingScope.SINGLETON})
export class LogService {
  log(msg: string) {
    console.log(msg);
  }
}

// Define a class to be bound via ctx.toProvider()
const uuidv4 = require('uuid/v4');
export class UuidProvider implements Provider<string> {
  value() {
    return uuidv4();
  }
}

// Register the local services
app.service(LogService);
app.service(UuidProvider, 'uuid');

export class MyController {
  constructor(
    @inject('services.uuid') private uuid: string,
    @inject('services.LogService') private log: LogService,
  ) {
  }

  greet(name: string) {
    this.log(`Greet request ${this.uuid} received: ${name}`);
    return `${this.uuid}: ${name}`;
  }
}

```


