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 authored and GitHub committed 2023-03-29 08:47:12 +02:00
1 parent 8ddb3952c0
commit 55e94d0b45
3 files changed
+11 -6

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/modules-sdk": patch
---
Checks if dependency is registered before resolving it
+1 -5
View File
@@ -7,7 +7,6 @@ import {
FilterableInventoryLevelProps, FilterableInventoryLevelProps,
FilterableReservationItemProps, FilterableReservationItemProps,
FindConfig, FindConfig,
IEventBusService,
IInventoryService, IInventoryService,
InventoryItemDTO, InventoryItemDTO,
InventoryLevelDTO, InventoryLevelDTO,
@@ -28,21 +27,19 @@ import ReservationItemService from "./reservation-item"
type InjectedDependencies = { type InjectedDependencies = {
manager: EntityManager manager: EntityManager
eventBusService: IEventBusService
inventoryItemService: InventoryItemService inventoryItemService: InventoryItemService
inventoryLevelService: InventoryLevelService inventoryLevelService: InventoryLevelService
reservationItemService: ReservationItemService reservationItemService: ReservationItemService
} }
export default class InventoryService implements IInventoryService { export default class InventoryService implements IInventoryService {
protected readonly manager_: EntityManager protected readonly manager_: EntityManager
protected readonly eventBusService_: IEventBusService | undefined
protected readonly inventoryItemService_: InventoryItemService protected readonly inventoryItemService_: InventoryItemService
protected readonly reservationItemService_: ReservationItemService protected readonly reservationItemService_: ReservationItemService
protected readonly inventoryLevelService_: InventoryLevelService protected readonly inventoryLevelService_: InventoryLevelService
constructor( constructor(
{ {
eventBusService,
manager, manager,
inventoryItemService, inventoryItemService,
inventoryLevelService, inventoryLevelService,
@@ -52,7 +49,6 @@ export default class InventoryService implements IInventoryService {
moduleDeclaration?: InternalModuleDeclaration moduleDeclaration?: InternalModuleDeclaration
) { ) {
this.manager_ = manager this.manager_ = manager
this.eventBusService_ = eventBusService
this.inventoryItemService_ = inventoryItemService this.inventoryItemService_ = inventoryItemService
this.inventoryLevelService_ = inventoryLevelService this.inventoryLevelService_ = inventoryLevelService
this.reservationItemService_ = reservationItemService this.reservationItemService_ = reservationItemService
@@ -75,7 +75,11 @@ export async function loadInternalModule(
for (const dependency of moduleDependencies) { for (const dependency of moduleDependencies) {
localContainer.register( localContainer.register(
dependency, dependency,
asFunction(() => container.resolve(dependency)) asFunction(() => {
return container.hasRegistration(dependency)
? container.resolve(dependency)
: undefined
})
) )
} }
} }