Why must programs declare 'with application of' for injection?
← DI Validation · Ref: Q672
Programs that use component injection must declare 'with application of AppName' (E08220). Without this linkage, the compiler cannot resolve which concrete implementations to inject.
LINKAGE SYNTAX
defines program MyProgram() with application of MyApp service as AbstractService! // Resolved from MyApp
WHY REQUIRED
The application definition is the wiring blueprint. It maps abstract types to concrete implementations. Without it, the compiler sees an injection point but has no way to resolve it.
MULTIPLE APPLICATIONS
Different programs can link to different applications:
ProdProgram() with application of ProductionApp TestProgram() with application of TestApp
Same abstract types, different implementations.
See Q668 for injectable contexts. See Q673 for missing registration. See Q674 for duplicate registration.
Example
defines module qa.divalidation.programlink defines component <?- Abstract audit service contract. -?> AuditService as abstract recordEvent() as abstract -> eventName as String default operator ? <?- Console-based audit implementation. -?> ConsoleAudit extends AuditService override recordEvent() -> eventName as String stdout <- Stdout() stdout.println(`Audit: ${eventName}`) default operator ? defines application <?- Application wiring for production. Maps abstract types to concrete implementations. -?> ProductionSetup register ConsoleAudit() as AuditService defines program <?- Program linked to application for injection. The 'with application of' clause enables injection resolution. -?> ProgramApplicationDemo() with application of ProductionSetup stdout <- Stdout() auditor as AuditService! auditor.recordEvent("application-started") stdout.println("Program linked to ProductionSetup application") stdout.println("Injection resolved through application wiring") auditor.recordEvent("demo-complete")
Common mistakes
E08220 — Programs that use component injection must declare 'with application of AppName' to link to a DI configuration. Without this linkage, the compiler has no application wiring blueprint to resolve which concrete implementations to inject. See ek9 -h E08220 for details.
Incorrect:
ProgramApplicationDemo()
Correct:
ProgramApplicationDemo() with application of ProductionSetup
Other ways to ask this
- What is E08220 program without application?
- How do I link a program to an application?
- What happens if I inject without an application?
Coming from another language?
Java: Spring ApplicationContext is implicit (classpath scanning). Python: Flask/Django auto-discover. Go: manual wiring in main(). Rust: manual wiring. EK9: explicit 'with application of' declaration links program to its DI configuration.
Keywords: E08220, define, injection, linkage, program, registration, DI, wiring, application, inject, validate