Why does EK9 reject an application that has no register statements?
← Dependency Injection · Ref: Q1313
An application is a dependency-injection registry: its whole purpose is to bind concrete components to the abstract types that programs inject. An empty application body has no purpose and is almost always an incomplete definition, so EK9 raises E07160 (implementation must be provided). Unlike a method, an application cannot be marked 'as abstract' - it must contain at least one register statement (or a block statement). The fix is to add the register lines that wire your components.
defines application GreetApp register ConsoleGreeter() as Greeter
See Q1113 for wiring several components. See Q231 for linking a program to an application.
Example
defines module qa.di.application.body defines component Greeter as abstract greet() as abstract -> name as String <- message as String? default operator ? ConsoleGreeter is Greeter override greet() -> name as String <- message as String: `Hello, ${name}!` default operator ? defines application //CORRECT: the application body provides at least one register statement, //so it is a meaningful DI registry (not an empty body -> E07160). GreetApp register ConsoleGreeter() as Greeter defines program ApplicationBodyDemo() with application of GreetApp stdout <- Stdout() greeter as Greeter! stdout.println(greeter.greet("World"))
Common mistakes
E07160 — An application with no register or block statements has an empty body. An application cannot be abstract and a registry with no bindings is meaningless, so EK9 raises E07160. Add at least one register statement that binds a concrete component to its abstract type. See ek9 -h E07160 for details.
Incorrect:
defines application GreetApp
Correct:
defines application //CORRECT: the application body provides at least one register statement,
Other ways to ask this
- What triggers E07160 implementation must be provided on an application?
- Why can't I declare an empty application block in EK9?
- How do I fix 'definition of application: implementation must be provided'?
Coming from another language?
Spring: an empty @Configuration class compiles silently and fails only at runtime when a bean is missing. Guice: an empty AbstractModule.configure() compiles and defers the error to injector creation. .NET: an empty service-collection setup compiles and surfaces missing-service errors at first resolve. EK9: an empty application is a compile-time error (E07160) - the registry must declare its bindings up front.
Keywords: application, E07160, registry, wiring, DI, empty, implementation, body, register