diff --git a/packages/repository/README.md b/packages/repository/README.md index f4807f3d3bf3..d8b25eac2e99 100644 --- a/packages/repository/README.md +++ b/packages/repository/README.md @@ -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