diff --git a/packages/backend-app-api/src/wiring/ServiceRegistry.ts b/packages/backend-app-api/src/wiring/ServiceRegistry.ts index 61f95ff4a4..25d777549c 100644 --- a/packages/backend-app-api/src/wiring/ServiceRegistry.ts +++ b/packages/backend-app-api/src/wiring/ServiceRegistry.ts @@ -39,7 +39,7 @@ function toInternalServiceFactory( factory: ServiceFactory, ): InternalServiceFactory { const f = factory as InternalServiceFactory; - if (f.$$type !== '@backstage/ServiceFactory') { + if (f.$$type !== '@backstage/BackendFeature') { throw new Error(`Invalid service factory, bad type '${f.$$type}'`); } if (f.version !== 'v1') { @@ -82,6 +82,13 @@ export class ServiceRegistry implements EnumerableServiceHolder { this.#implementations = new Map(); } + add(serviceFactory: ServiceFactory) { + this.#providedFactories.set( + serviceFactory.service.id, + toInternalServiceFactory(serviceFactory), + ); + } + #resolveFactory( ref: ServiceRef, pluginId: string, diff --git a/packages/backend-app-api/src/wiring/types.ts b/packages/backend-app-api/src/wiring/types.ts index 36e2dede30..e2cc299541 100644 --- a/packages/backend-app-api/src/wiring/types.ts +++ b/packages/backend-app-api/src/wiring/types.ts @@ -19,6 +19,7 @@ import { ExtensionPoint, ServiceRef, ServiceFactoryOrFunction, + ServiceFactory, } from '@backstage/backend-plugin-api'; /** @@ -39,6 +40,7 @@ export interface CreateSpecializedBackendOptions { export interface ServiceHolder { get(api: ServiceRef, pluginId: string): Promise | undefined; + add(serviceFactory: ServiceFactory): void; } /**