---
lang: en
title: 'API docs: repository.definerepositoryclass'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
editurl: https://github.com/strongloop/loopback-next/tree/master/packages/repository
permalink: /doc/en/lb4/apidocs.repository.definerepositoryclass.html
---

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

[Home](./index.md) &gt; [@loopback/repository](./repository.md) &gt; [defineRepositoryClass](./repository.definerepositoryclass.md)

## defineRepositoryClass() function

Create (define) a repository class for the given model.

See also `defineCrudRepositoryClass` and `defineKeyValueRepositoryClass` for convenience wrappers providing repository class factory for the default CRUD and KeyValue implementations.

\*\*❗️IMPORTANT: The compiler (TypeScript 3.8) is not able to correctly infer generic arguments `M` and `R` from the class constructors provided in function arguments. You must always provide both M and R types explicitly.\*\*

<b>Signature:</b>

```typescript
export declare function defineRepositoryClass<M extends typeof Model, R extends Repository<PrototypeOf<M>>>(modelClass: M, baseRepositoryClass: BaseRepositoryClass<M, R>): ModelRepositoryClass<PrototypeOf<M>, R>;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  modelClass | M | A model class such as <code>Address</code>. |
|  baseRepositoryClass | [BaseRepositoryClass](./repository.baserepositoryclass.md)<!-- -->&lt;M, R&gt; | Repository implementation to use as the base, e.g. <code>DefaultCrudRepository</code>. |

<b>Returns:</b>

[ModelRepositoryClass](./repository.modelrepositoryclass.md)<!-- -->&lt;[PrototypeOf](./repository.prototypeof.md)<!-- -->&lt;M&gt;, R&gt;

## Example


```ts
const AddressRepository = defineRepositoryClass<
  typeof Address,
  DefaultEntityCrudRepository<
   Address,
   typeof Address.prototype.id,
   AddressRelations
  >,
>(Address, DefaultCrudRepository);

```


