Aurelia 2, DI feedback and woes

note: using 0.6.0

given this constructor

@singleton()
export default class App {
  constructor(
    private readonly apolloServerConfig: ApolloServerConfig,
    @optional(InjectToken.GraphHost) private readonly host: string = '0.0.0.0',
    @optional(InjectToken.GraphPort) private readonly port: number = 4000,
    @inject(InjectToken.CorsOrigins) private readonly origins: string,
    @inject(LoggerDefault) private readonly log: Logger,
  ) {}

and

@singleton()
export default class ApolloServerConfig implements Config {
  constructor(
    @all(InjectToken.GraphFieldResolvers)
    private readonly graphResolvers: Array<ResolversFactory>,
    @inject(InjectToken.EngineApiKey)
    private readonly engineApiKey: string,
    @inject(InjectToken.GraphApiKey)
    private readonly serviceApiKey: string,
    @inject(InjectToken.GraphSkipApiKey)
    private readonly skipApiKey: string,
  ) {}

when I call container.get(App)

I get this

error:    uncaughtException: Code 5
Error: Code 5
    at Object.error (/Users/calebcushing/IdeaProjects/service-graph/node_modules/@aurelia/kernel/src/reporter.ts:58:61)
    at validateKey (/Users/calebcushing/IdeaProjects/service-graph/node_modules/@aurelia/kernel/src/di.ts:1012:20)
    at Container.get (/Users/calebcushing/IdeaProjects/service-graph/node_modules/@aurelia/kernel/src/di.ts:845:5)
    at Object.invoke (/Users/calebcushing/IdeaProjects/service-graph/node_modules/@aurelia/kernel/src/di.ts:630:21)
    at Factory.construct (/Users/calebcushing/IdeaProjects/service-graph/node_modules/@aurelia/kernel/src/di.ts:540:22)
    at Resolver.resolve (/Users/calebcushing/IdeaProjects/service-graph/node_modules/@aurelia/kernel/src/di.ts:476:37)
    at Container.get (/Users/calebcushing/IdeaProjects/service-graph/node_modules/@aurelia/kernel/src/di.ts:860:27)
    at Object.<anonymous> (/Users/calebcushing/IdeaProjects/service-graph/src/index.ts:18:6)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Module.m._compile (/Users/calebcushing/IdeaProjects/service-graph/node_modules/ts-node/src/index.ts:473:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/calebcushing/IdeaProjects/service-graph/node_modules/ts-node/src/index.ts:476:12)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
    at internal/main/run_main_module.js:17:11 

on the pro side, the failing line number is in there, on the conn side, this didn’t have a helpful message at all. Turns out after much digging it wasn’t finding the key for the first parameter apolloServerConfig. What would be helpful here is to include the “parent” object that dependencies are trying to be resolved for, and if possible which position is failing.

When I added @Inject(ApolloServerConfig) to that it works fine, but I thought I shouldn’t need inject on managed types? Perhaps since I’m just using the @aurelia/kernel there is something more I need to do to make the magic happen?

1 Like

Here’s another error, still working my way through this, but it looks like it’s trying to register an entity… not sure why… would be useful to know which object it was trying to inject this into, and have some information about this one in the error message.

error:    Error: Unable to autoregister dependency
    at Container.register (/Users/calebcushing/IdeaProjects/service-graph/node_modules/@aurelia/kernel/src/di.ts:712:13)
    at Container.register (/Users/calebcushing/IdeaProjects/service-graph/node_modules/@aurelia/kernel/src/di.ts:756:18)
    at Container.register (/Users/calebcushing/IdeaProjects/service-graph/node_modules/@aurelia/kernel/src/di.ts:756:18)
1 Like

A way to solve the cryptic error message is to register debug helper:

import { DebugResigration } from '@aurelia/debug'

...
  .register(DebugRegistration)
2 Likes

that class doesn’t appear to exist in the latest nightly. Even if it did, my latest error was happening before I could register anything.

1 Like

If I register as a new user would I also face the same issue?