diff --git a/src/shared/infrastructure/http/factories/ServiceFactory.ts b/src/shared/infrastructure/http/factories/ServiceFactory.ts index 218a8672..87fc9e2f 100644 --- a/src/shared/infrastructure/http/factories/ServiceFactory.ts +++ b/src/shared/infrastructure/http/factories/ServiceFactory.ts @@ -224,28 +224,17 @@ export class ServiceFactory { }; } - // Create saga with appropriate state store - let cardCollectionSaga: CardCollectionSaga; - if (useInMemoryEvents) { - const stateStore = new InMemorySagaStateStore(); - cardCollectionSaga = new CardCollectionSaga( - sharedServices.feedService as any, // Will be properly typed when used - stateStore, - ); - } else { - const stateStore = new RedisSagaStateStore(redisConnection!); - cardCollectionSaga = new CardCollectionSaga( - sharedServices.feedService as any, // Will be properly typed when used - stateStore, - ); - } + // Create appropriate saga state store + const sagaStateStore = useInMemoryEvents + ? new InMemorySagaStateStore() + : new RedisSagaStateStore(redisConnection!); return { ...sharedServices, redisConnection: redisConnection, eventPublisher, createEventSubscriber, - cardCollectionSaga, + sagaStateStore, }; } diff --git a/src/shared/infrastructure/processes/FeedWorkerProcess.ts b/src/shared/infrastructure/processes/FeedWorkerProcess.ts index 6ada6fbe..6a7579dc 100644 --- a/src/shared/infrastructure/processes/FeedWorkerProcess.ts +++ b/src/shared/infrastructure/processes/FeedWorkerProcess.ts @@ -40,15 +40,10 @@ export class FeedWorkerProcess extends BaseWorkerProcess { ): Promise { const useCases = UseCaseFactory.createForWorker(repositories, services); - // Create saga with appropriate state store based on event system type - const useInMemoryEvents = process.env.USE_IN_MEMORY_EVENTS === 'true'; - const stateStore = useInMemoryEvents - ? new InMemorySagaStateStore() - : new RedisSagaStateStore(services.redisConnection!); - + // Create saga with proper use case dependency and state store from services const cardCollectionSaga = new CardCollectionSaga( useCases.addActivityToFeedUseCase, - stateStore, + services.sagaStateStore, ); const cardAddedToLibraryHandler = new CardAddedToLibraryEventHandler(