Skip to content

Commit

Permalink
refactor: composition root for personal dashboard service (#8280)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Sep 27, 2024
1 parent 6655b2d commit 829fda7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/lib/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './events/createEventsService';
export * from './instance-stats/createInstanceStatsService';
export * from './feature-lifecycle/createFeatureLifecycle';
export * from './playground/createPlaygroundService';
export * from './personal-dashboard/createPersonalDashboardService';
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Db } from '../../db/db';
import type { IUnleashConfig } from '../../types';
import { PersonalDashboardService } from './personal-dashboard-service';
import { PersonalDashboardReadModel } from './personal-dashboard-read-model';
import { FakePersonalDashboardReadModel } from './fake-personal-dashboard-read-model';
import { ProjectOwnersReadModel } from '../project/project-owners-read-model';
import { FakeProjectOwnersReadModel } from '../project/fake-project-owners-read-model';
import { ProjectReadModel } from '../project/project-read-model';
import { FakeProjectReadModel } from '../project/fake-project-read-model';

export const createPersonalDashboardService = (
db: Db,
config: IUnleashConfig,
) => {
return new PersonalDashboardService(
new PersonalDashboardReadModel(db),
new ProjectOwnersReadModel(db),
new ProjectReadModel(db, config.eventBus, config.flagResolver),
);
};

export const createFakePersonalDashboardService = () => {
return new PersonalDashboardService(
new FakePersonalDashboardReadModel(),
new FakeProjectOwnersReadModel(),
new FakeProjectReadModel(),
);
};
24 changes: 7 additions & 17 deletions src/lib/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,10 @@ import {
} from '../features/onboarding/createOnboardingService';
import { OnboardingService } from '../features/onboarding/onboarding-service';
import { PersonalDashboardService } from '../features/personal-dashboard/personal-dashboard-service';
import { PersonalDashboardReadModel } from '../features/personal-dashboard/personal-dashboard-read-model';
import { FakePersonalDashboardReadModel } from '../features/personal-dashboard/fake-personal-dashboard-read-model';
import { ProjectOwnersReadModel } from '../features/project/project-owners-read-model';
import { FakeProjectOwnersReadModel } from '../features/project/fake-project-owners-read-model';
import { FakeProjectReadModel } from '../features/project/fake-project-read-model';
import { ProjectReadModel } from '../features/project/project-read-model';
import {
createFakePersonalDashboardService,
createPersonalDashboardService,
} from '../features/personal-dashboard/createPersonalDashboardService';

export const createServices = (
stores: IUnleashStores,
Expand Down Expand Up @@ -408,17 +406,9 @@ export const createServices = (
: createFakeOnboardingService(config).onboardingService;
onboardingService.listen();

// TODO: move to composition root
const personalDashboardService = new PersonalDashboardService(
db
? new PersonalDashboardReadModel(db)
: new FakePersonalDashboardReadModel(),

db ? new ProjectOwnersReadModel(db) : new FakeProjectOwnersReadModel(),
db
? new ProjectReadModel(db, config.eventBus, config.flagResolver)
: new FakeProjectReadModel(),
);
const personalDashboardService = db
? createPersonalDashboardService(db, config)
: createFakePersonalDashboardService();

return {
accessService,
Expand Down

0 comments on commit 829fda7

Please sign in to comment.