diff --git a/packages/support/src/services/index.ts b/packages/support/src/services/index.ts index 858e01c7..4ccb7651 100644 --- a/packages/support/src/services/index.ts +++ b/packages/support/src/services/index.ts @@ -3,5 +3,6 @@ export { ServiceProvider, } +export * from "./isServiceProvider"; export * from "./isServiceProviderConstructor"; export * from "./ServiceProviderClassBlueprint" \ No newline at end of file diff --git a/packages/support/src/services/isServiceProvider.ts b/packages/support/src/services/isServiceProvider.ts new file mode 100644 index 00000000..d7e8fb54 --- /dev/null +++ b/packages/support/src/services/isServiceProvider.ts @@ -0,0 +1,27 @@ +import { isset } from "@aedart/support/misc"; +import { isServiceProviderConstructor } from "./isServiceProviderConstructor"; +import ServiceProvider from "./ServiceProvider"; + +/** + * Determine if given object is a [ServiceProvider]{@link import('@aedart/contracts/support/services').ServiceProvider} + * + * @param {object} instance + * + * @returns {boolean} + */ +export function isServiceProvider(instance: object): boolean +{ + if (!isset(instance) || typeof instance !== 'object') { + return false; + } + + if (instance instanceof ServiceProvider) { + return true; + } + + if (!Reflect.has(instance, 'constructor')) { + return false; + } + + return isServiceProviderConstructor(instance.constructor); +} \ No newline at end of file