Skip to content

Commit f57b1c0

Browse files
authored
Merge pull request #259 from proto-kit/fix/next-15-dependency-injection
Refactor injection token definitions for dynamic keys
2 parents 448695e + 99aafd8 commit f57b1c0

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

packages/protocol/src/protocol/Protocol.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ import { ProtocolEnvironment } from "./ProtocolEnvironment";
2828
import { ProvableBlockHook } from "./ProvableBlockHook";
2929
import { TransitioningProtocolModule } from "./TransitioningProtocolModule";
3030

31+
/**
32+
* This is a mapping of abstract classes to their respective injection tokens.
33+
* Keys are the abstract classes names, which need to be set dynamically
34+
* and can't be hardcoded since producing optimized builds may mangle the
35+
* class names, making them different from the ones in the source code.
36+
*/
3137
const PROTOCOL_INJECTION_TOKENS: Record<string, string> = {
32-
ProvableTransactionHook: "ProvableTransactionHook",
33-
ProvableBlockHook: "ProvableBlockHook",
34-
ProvableSettlementHook: "ProvableSettlementHook",
38+
[ProvableTransactionHook.name]: "ProvableTransactionHook",
39+
[ProvableBlockHook.name]: "ProvableBlockHook",
40+
[ProvableSettlementHook.name]: "ProvableSettlementHook",
3541
};
3642

3743
export type ProtocolModulesRecord = ModulesRecord<
@@ -162,7 +168,7 @@ export class Protocol<
162168

163169
implementingModules.forEach(([key]) => {
164170
this.container.register(
165-
abstractType.name,
171+
newInjectionToken,
166172
{ useToken: key },
167173
{ lifecycle: Lifecycle.ContainerScoped }
168174
);
@@ -175,7 +181,7 @@ export class Protocol<
175181

176182
// Register default (noop) version
177183
this.container.register(
178-
abstractType.name,
184+
newInjectionToken,
179185
{ useClass: defaultType },
180186
{ lifecycle: Lifecycle.ContainerScoped }
181187
);

0 commit comments

Comments
 (0)