fix(modules-sdk): check if dependency is registered (#3620)

* fix: check if dependency is registered

* changeset
This commit is contained in:
Carlos R. L. Rodrigues
2023-03-29 03:47:12 -03:00
committed by GitHub
parent 8ddb3952c0
commit 55e94d0b45
3 changed files with 11 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/modules-sdk": patch
---
Checks if dependency is registered before resolving it

View File

@@ -7,7 +7,6 @@ import {
FilterableInventoryLevelProps,
FilterableReservationItemProps,
FindConfig,
IEventBusService,
IInventoryService,
InventoryItemDTO,
InventoryLevelDTO,
@@ -28,21 +27,19 @@ import ReservationItemService from "./reservation-item"
type InjectedDependencies = {
manager: EntityManager
eventBusService: IEventBusService
inventoryItemService: InventoryItemService
inventoryLevelService: InventoryLevelService
reservationItemService: ReservationItemService
}
export default class InventoryService implements IInventoryService {
protected readonly manager_: EntityManager
protected readonly eventBusService_: IEventBusService | undefined
protected readonly inventoryItemService_: InventoryItemService
protected readonly reservationItemService_: ReservationItemService
protected readonly inventoryLevelService_: InventoryLevelService
constructor(
{
eventBusService,
manager,
inventoryItemService,
inventoryLevelService,
@@ -52,7 +49,6 @@ export default class InventoryService implements IInventoryService {
moduleDeclaration?: InternalModuleDeclaration
) {
this.manager_ = manager
this.eventBusService_ = eventBusService
this.inventoryItemService_ = inventoryItemService
this.inventoryLevelService_ = inventoryLevelService
this.reservationItemService_ = reservationItemService

View File

@@ -75,7 +75,11 @@ export async function loadInternalModule(
for (const dependency of moduleDependencies) {
localContainer.register(
dependency,
asFunction(() => container.resolve(dependency))
asFunction(() => {
return container.hasRegistration(dependency)
? container.resolve(dependency)
: undefined
})
)
}
}