Skip to content
GitHub

Service

function in meocord/decorator Since 4.0.0

Service<T>(): (
  target: new (...args: any[]) => T,
  propertyKey?: string | symbol,
) => void

Marks a class as a service, which controllers and other services inject by its type.

Use it for logic and state that outlive one call: database access, API clients, caches, counters. The app makes one instance, shared by every class that injects it; list it in @MeoCord({ services }) when nothing injects it. For a value that is not a class, such as a config object or a client made by a factory, use a provider and Inject.

Returns

Returns a property decorator.

(target: new (...args: any[]) => T, propertyKey?: string | symbol) => void

Examples

TypeScript
@Service()
export class GreetingService {
  greet(name: string): string {
    return `Hello, ${name}!`
  }
}