Skip to content

Commit d8a3ecd

Browse files
committed
Disallow duplicate registration
1 parent b7488e6 commit d8a3ecd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/v1/src/di/context.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ export class Context {
2525
registerConstructor(Entity: ConstructorUnknown): this {
2626
this.logger.log(`Registering "${Entity.name}" …`)
2727

28-
if (!this.registry.hasCreator(Entity)) {
29-
this.registry.addCreator(Entity, async (...dependencies) => new Entity(...dependencies as never))
28+
if (this.registry.hasCreator(Entity)) {
29+
throw new Error(`Cannot register: "${Entity.name}" is already registered`)
3030
}
3131

32+
this.registry.addCreator(Entity, async (...dependencies) => new Entity(...dependencies as never))
33+
3234
return this
3335
}
3436

0 commit comments

Comments
 (0)