Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/repository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,24 @@ ctx.bind('dataSources.memory').to(ds);
ctx.bind('repositories.noteRepo').toClass(MyNoteRepository);
```

#### Using the Repository Mixin for Application
A Repository Mixin is available for Application that provides convenience methods for binding and instantiating a repository class. Bound instances can be used anywhere in your application using Dependency Injection. An array set to the key `repositories` can be passed to the constructor or the `.repository(RepositoryClass)` function can be used. The mixin will also instantiate any repositories declared by a component in its constructor using the `repositories` key.

Repositories will be bound to the key `repositories.RepositoryClass` where `RepositoryClass` is the name of the Repository class being bound.
```ts
import { Application } from '@loopback/core';
import { RepositoryMixin } from '@loopback/repository';
import { ProductRepository, CategoryRepository } from './repository';

// Using the Mixin
class MyApplication extends RepositoryMixin(Application) {}

// MyRepository will be bound to key `repositories.ProductRepository`
const app = new MyApplication({repositories: [ProductRepository]});
// MyRepository2 will be bound to key `repositories.CategoryRepository`
app.repository(CategoryRepository);
```

### Compose repositories and controllers in a context

```ts
Expand Down