backend-app-api: add add method to ServiceRegistry
Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
committed by
Patrik Oldsberg
parent
966e376056
commit
108728f5fe
@@ -39,7 +39,7 @@ function toInternalServiceFactory<TService, TScope extends 'plugin' | 'root'>(
|
||||
factory: ServiceFactory<TService, TScope>,
|
||||
): InternalServiceFactory<TService, TScope> {
|
||||
const f = factory as InternalServiceFactory<TService, TScope>;
|
||||
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<unknown>,
|
||||
pluginId: string,
|
||||
|
||||
@@ -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<T>(api: ServiceRef<T>, pluginId: string): Promise<T> | undefined;
|
||||
add(serviceFactory: ServiceFactory): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user