Skip to content

Commit

Permalink
fix: return same EM fork for EM from core and driver packages (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
B4nan committed Aug 14, 2022
1 parent 5137acd commit d6789f6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/mikro-orm.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ export function createEntityManagerProvider(
entityManager: Type = EntityManager,
contextName?: string,
): Provider<EntityManager> {
if (!contextName && entityManager !== EntityManager) {
return {
provide: entityManager,
scope,
useFactory: (em: EntityManager) => em, // just a simle alias, unlike `useExisting` from nest, this works with request scopes too
inject: [EntityManager], // depend on the EM from core package
};
}

return {
provide: contextName ? getEntityManagerToken(contextName) : entityManager,
scope,
Expand Down

0 comments on commit d6789f6

Please sign in to comment.