How to use entity repository in service without injecting
See original GitHub issueThe mikro-orm docs have a way to create a repository https://mikro-orm.io/docs/next/repositories however from the documentations and example there has been no way to use the repository like you would in typeorm
@Repository(Author)
export class CustomAuthorRepository extends EntityRepository<Author> {
// your custom methods...
public findAndUpdate(...) {
// ...
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Inject repository in service without DI framework - Stack Overflow
I use JAX-RS (Jersey implementation) and Jetty as an embedded servlet container.I use JPA (Hibernate implementation) and an H2 in-memory ...
Read more >How *not* to inject services in entities - // thinkbeforecoding
The usual way to work it out is to hold a reference to a data access object or a repository and to load...
Read more >Services and dependency injection in Drupal 8+
As a developer, it is best practice to access any of the services provided ... Note: It's not possible to inject services to...
Read more >How not to do dependency injection - the static or singleton ...
You can use an IoC container without doing dependency injection and in ... NET MVC Controller -> Service Layer -> Repository -> Entity...
Read more >Use dependency injection in .NET Azure Functions
The use of constructor injection requires that you do not use static classes for injected services or for your function classes.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I still don’t follow what you mean. So you don’t like the
InjectRepository
bit, but are fine with using nest DI in general? You can make the repository injectable, the decorator is needed only when you do not have custom implementation.This is how the repositories are registered, you can use the same way to register your custom repository:
https://github.com/mikro-orm/nestjs/blob/master/src/mikro-orm.providers.ts#L63
Or as long as you name your custom repository the same way as
getRepositoryToken()
helper would, you don’t need to do anything special:Just put it to the class/interface:
You need both,
EntityRepositoryType
is for TS inference,customRepository
is for the ORM runtime metadata.