E08210: program uses injection but application has no registration for the required component type

Category: E08xxx Pre-IR checks (flow analysis) · Reported in phase: PRE_IR_CHECKS · Classification: DI_MISSING_REGISTRATION · All error codes

What went wrong

A program uses component injection (via '!' suffix) but the linked application has no registration for the required abstract component type. Every injected component must have a concrete implementation registered.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 230 (What happens if I forget to register a dependency in EK9?)
  • ek9 -q 798 (What happens with missing or duplicate component registra...)
  • ek9 -q 227 (How does EK9 validate dependency injection at compile time?)
  • ek9 -q 324 (What is the EK9 equivalent of Spring @Autowired?)
  • ek9 -q 329 (How does EK9 DI compare to Google Guice modules?)

How to fix it

  1. Add the missing registration to the application block
  2. Or remove the injection if the dependency is not needed
  3. Check that the abstract type name matches exactly

See also

  • E08210: missing registration (this error)
  • E08220: program without application
  • E08190: circular dependency

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E08210: program uses injection but application has no registration for the required component type

#!ek9
defines module error.e08210.bad

  defines component

    AbstractA as abstract
      doWorkA() as abstract
        <- rtn as Boolean?

      default operator ?

    AbstractB as abstract
      doWorkB() as abstract
        <- rtn as Boolean?

      default operator ?

    ComponentA is AbstractA
      svcB as AbstractB!

      override doWorkA()
        <- rtn as Boolean: true

      default operator ?

    ComponentB is AbstractB

      override doWorkB()
        <- rtn as Boolean: true

      default operator ?

  defines application

    missingApp
      register ComponentA() as AbstractA

Fixed: Register a component for every abstract one that is injected - before the one it is injected into

#!ek9
defines module error.e08210.good.fix

  defines component

    AbstractA as abstract
      doWorkA() as abstract
        <- rtn as Boolean?

      default operator ?

    AbstractB as abstract
      doWorkB() as abstract
        <- rtn as Boolean?

      default operator ?

    ComponentA is AbstractA
      svcB as AbstractB!

      override doWorkA()
        <- rtn as Boolean: true

      default operator ?

    ComponentB is AbstractB

      override doWorkB()
        <- rtn as Boolean: true

      default operator ?

  defines application

    missingApp
      register ComponentB() as AbstractB
      register ComponentA() as AbstractA

Fixed: Register every component that is injected

#!ek9
defines module error.e08210.good

  defines component

    AbstractA as abstract
      doWorkA() as abstract
        <- rtn as Boolean?
      default operator ?

    AbstractB as abstract
      doWorkB() as abstract
        <- rtn as Boolean?
      default operator ?

    ComponentB is AbstractB
      override doWorkB()
        <- rtn as Boolean: true
      default operator ?

    ComponentA is AbstractA
      svcB as AbstractB!
      override doWorkA()
        <- rtn as Boolean: svcB.doWorkB()
      default operator ?

  defines application

    completeApp
      register ComponentB() as AbstractB
      register ComponentA() as AbstractA

Questions and answers

These Q&A entries show E08210 and its fix: