diff --git a/package.json b/package.json index 58555fb..1fb9e70 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cordis", "description": "AOP Framework for Modern JavaScript Applications", - "version": "3.5.1", + "version": "3.5.2", "sideEffects": false, "main": "lib/index.cjs", "module": "lib/index.mjs", diff --git a/src/context.ts b/src/context.ts index 35f83fe..1edd9bb 100644 --- a/src/context.ts +++ b/src/context.ts @@ -261,6 +261,7 @@ export class Context { provide(name: string, value?: any, builtin?: boolean) { const internal = Context.ensureInternal.call(this.root) + if (name in internal) return const key = Symbol(name) internal[name] = { type: 'service', key, builtin } this.root[key] = value @@ -268,13 +269,13 @@ export class Context { accessor(name: string, options: Omit) { const internal = Context.ensureInternal.call(this.root) - internal[name] = { type: 'accessor', ...options } + internal[name] ||= { type: 'accessor', ...options } } alias(name: string, aliases: string[]) { const internal = Context.ensureInternal.call(this.root) for (const key of aliases) { - internal[key] = { type: 'alias', name } + internal[key] ||= { type: 'alias', name } } } diff --git a/tests/service.spec.ts b/tests/service.spec.ts index 4a6232b..13617c2 100644 --- a/tests/service.spec.ts +++ b/tests/service.spec.ts @@ -58,7 +58,8 @@ describe('Service', () => { root.on('internal/warning', warn) root.alias('bar', ['baz']) root.mixin('foo', ['bar']) - root.provide('foo', { bar: 1 }) + root.provide('foo') + root.foo = { bar: 1 } // foo is a service expect(root.get('foo')).to.be.ok