1 ---
2 sidebar_label: "prefer-container-registration-keys"
3 ---
4
5 export const metadata = {
6 title: `prefer-container-registration-keys - ESLint plugin rules`,
7 }
8
9 # {metadata.title}
10
11 This rule prefers `ContainerRegistrationKeys.*` members over magic strings in `resolve(...)` calls.
12
13 ## Severity
14
15 `warn`. This rule is enabled in the [recommended](../../page.mdx#recommended) preset.
16
17 ## What it Targets
18
19 This rule targets all files in your project. It reports calls to `resolve(...)` that pass a known registration-key string, such as `"query"` or `"logger"`, instead of the matching `ContainerRegistrationKeys` member.
20
21 The following code is reported by the rule:
22
23 ```ts title="src/api/example.ts"
24 // non-compliant
25 const query = req.scope.resolve("query")
26 ```
27
28 Instead, use the `ContainerRegistrationKeys` enum:
29
30 ```ts title="src/api/example.ts"
31 // compliant
32 import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
33
34 const query = req.scope.resolve(
35 ContainerRegistrationKeys.QUERY
36 )
37 ```
38
39 ## Why it's Important
40
41 The `ContainerRegistrationKeys` enum gives you a single, type-safe source for registration keys. Using it avoids typos in magic strings and makes resolved dependencies easier to find and refactor.
42
43 Learn more in the [Medusa Container documentation](!docs!/learn/fundamentals/medusa-container).
44
45 ## Fixable
46
47 This rule is auto-fixable. Run the linter with the `--fix` option to apply the fix automatically.
48
49 ## Turn it Off
50
51 To turn off this rule, set it to `off` in your ESLint configuration:
52
53 ```ts title="eslint.config.ts"
54 import { defineConfig } from "eslint/config"
55 import medusa from "@medusajs/eslint-plugin"
56
57 export default defineConfig([
58 ...medusa.configs.recommended,
59 {
60 rules: {
61 "@medusajs/prefer-container-registration-keys": "off",
62 },
63 },
64 ])
65 ```
66
67 Or disable it for a single line using an inline comment:
68
69 ```ts
70 // eslint-disable-next-line @medusajs/prefer-container-registration-keys
71 const query = req.scope.resolve("query")
72 ```