Skip to content

Commit

Permalink
Add interface for Service Registrar
Browse files Browse the repository at this point in the history
  • Loading branch information
aedart committed Apr 13, 2024
1 parent d4120d0 commit 3a3e03b
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
101 changes: 101 additions & 0 deletions packages/contracts/src/support/services/Registrar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import ServiceProvider from "./ServiceProvider";
import ServiceProviderConstructor from "./ServiceProviderConstructor";


/**
* Service Registrar
*
* Able to register and boot service providers.
*/
export default interface Registrar
{
/**
* Register a service provider
*
* @param {ServiceProvider | ServiceProviderConstructor} provider
* @param {boolean} [boot=true]
*
* @returns {Promise<boolean>} False if already registered
*
* @async
*/
register(provider: ServiceProvider | ServiceProviderConstructor, boot?: boolean): Promise<boolean>;

/**
* Register multiple service providers
*
* @param {(ServiceProvider | ServiceProviderConstructor)[]} providers
* @param {boolean} [boot=true]
* @param {boolean} [safe=true] If true, given providers are only booted after all providers have been registered.
*
* @returns {Promise<boolean>}
*/
registerMultiple(providers: (ServiceProvider | ServiceProviderConstructor)[], boot?: boolean, safe?: boolean): Promise<boolean>;

/**
* Determine if service provider has already been registered
*
* @param {ServiceProvider | ServiceProviderConstructor} provider
*
* @returns {boolean}
*/
isRegistered(provider: ServiceProvider | ServiceProviderConstructor): boolean

/**
* Get the service providers that are registered
*
* @returns {ServiceProvider[]}
*/
get registered(): ServiceProvider[];

/**
* Boot given service provider
*
* @param {ServiceProvider} provider
*
* @returns {Promise<boolean>} False if provider has already been booted
*
* @async
*/
boot(provider: ServiceProvider): Promise<boolean>;

/**
* Boots all given service providers
*
* **Note**: _Method skips providers that have already been booted!_
*
* @param {ServiceProvider[]} providers
*
* @returns {Promise<boolean>}
*
* @async
*/
bootMultiple(providers: ServiceProvider[]): Promise<boolean>;

/**
* Determine if service provider has already been booted
*
* @param {ServiceProvider} provider
*
* @returns {boolean}
*/
hasBooted(provider: ServiceProvider): boolean;

/**
* Get the service providers that have been booted
*
* @returns {ServiceProvider[]}
*/
get booted(): ServiceProvider[];

/**
* Resolves service provider
*
* @param {ServiceProvider | ServiceProviderConstructor} provider
*
* @returns {ServiceProvider} Resolved service provider instance
*
* @throws {RegistrationException}
*/
resolveProvider(provider: ServiceProvider | ServiceProviderConstructor): ServiceProvider;
}
2 changes: 2 additions & 0 deletions packages/contracts/src/support/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
*/
export const SUPPORT_SERVICES: unique symbol = Symbol('@aedart/contracts/support/services');

import Registrar from "./Registrar";
import ServiceProvider from "./ServiceProvider";
import ServiceProviderConstructor from "./ServiceProviderConstructor";
export {
type Registrar,
type ServiceProvider,
type ServiceProviderConstructor,
}
Expand Down

0 comments on commit 3a3e03b

Please sign in to comment.