# RegisterMongooseService

`function` in `plugin-mongoose` · v0.2.1

<https://docs.seedcord.org/packages/plugin-mongoose/0.2.1/functions/register-mongoose-service>

Registers a database service with a typed key.

Associates a service class with a key for dependency injection. The service becomes available via `core.db.services[key]`.

The decorated class declares its schema as a `public static schema` member, which the plugin reads to build the model once the connection is open. A class without one is a compile error.

```ts
RegisterMongooseService<TService>(
    key: TService,
    options?: MongooseServiceRegistrationOptions
): <
    Ctor extends Constructor<MongooseServices[TService]> & {
        schema: mongoose.Schema;
    }
>(
    ctor: Ctor
) => void
```

Registers a database service with a typed key.

Associates a service class with a key for dependency injection. The service becomes available via `core.db.services[key]`.

The decorated class declares its schema as a `public static schema` member, which the plugin reads to build the model once the connection is open. A class without one is a compile error.

Parameters.

- `key` `TService` — Service key for registration and type-safe access
- `options?` `MongooseServiceRegistrationOptions` — Additional registration options

Returns `<Ctor extends Constructor<MongooseServices[TService]> & { schema: mongoose.Schema; }>(ctor: Ctor) => void`.
