Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-crews-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/modules-sdk": patch
---

Checks if dependency is registered before resolving it
6 changes: 1 addition & 5 deletions packages/inventory/src/services/inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
FilterableInventoryLevelProps,
FilterableReservationItemProps,
FindConfig,
IEventBusService,
IInventoryService,
InventoryItemDTO,
InventoryLevelDTO,
Expand All @@ -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,
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion packages/modules-sdk/src/loaders/utils/load-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
)
}
}
Expand Down