ek9_add_application
Appends the application to the file's 'defines application' block (created if absent), one 'register Component() as Interface' line per registration; answers status, edits[] and summary, with a would-fail carrying the compiler's own diagnostics.
When to use it
'Add a DI application DemoApp wiring V8 as Engine' is one call with file, name and registrations:[{component, as}] - no line needed. The same construct is production wiring (DemoApp) and test substitution (TestApp); there is no mocking framework.
When not to use it
- Defining the COMPONENT itself (the concrete or abstract base) - use
ek9_new_constructmode:'component'; applications register components, they do not define them. - Authoring the program or @Test that binds via 'with application of <App>' - use
ek9_add_program(isTest:true, application:'TestApp' for tests); author the application here first.
Details
Registrations (>=1 required — a bare shell does not compile) take two forms: supply 'as' for 'register Component() as Interface' (bind concrete to trait/component interface), or omit 'as' for a bare 'register Component()' (service-genus / HTTP-routing targets); optional 'aspects' list renders 'with aspect of A(), B()' for AOP (a bare 'A' becomes 'A()', a constructor call like 'A("audit")' is kept; 'as' is required with it), and components may be fully-qualified. Multiple applications share one 'defines application' block — the tool appends under an existing block or creates one. A duplicate application name in the SAME module (different modules are fine) or one interface bound twice in one app (E08230 DI_DUPLICATE_REGISTRATION) surfaces as would-fail from the dry-run gate.
Arguments
| Argument | Type | Required | What it is |
|---|---|---|---|
file | string | yes | Workspace-relative path to the .ek9 module file the application is appended to (the 'defines application' block is created if absent). |
name | string | yes | Application name (PascalCase), e.g. 'DemoApp'. |
registrations | array of object | DI registrations (>=1): [{component, as?, aspects?}]. Two forms: omit 'as' for a bare 'register Component()' (inject the concrete type), or supply 'as' for 'register Component() as Interface' (inject via the interface); 'aspects' (needs 'as') add 'with aspect of A()[, B()]' for AOP. |
It also takes the arguments every tool takes.
Recorded calls
Real calls, recorded against small projects and checked on every build - a changed answer fails it. 3 of the 4 recorded are shown.
Application aspect without interface rejected
Request
{
"dryRun" : true,
"file" : "main.ek9",
"name" : "AspectApp",
"registrations" : [ {
"aspects" : [ "SilentAspect()" ],
"component" : "V8"
} ]
}
Response
{
"conflicts" : [ ],
"edits" : [ ],
"error" : {
"message" : "registration of 'V8' names an aspect but no 'as' interface - 'with aspect of' follows 'register X() as Interface', so give 'as' too"
},
"meta" : {
"serverMs" : "<timing>"
},
"status" : "error",
"summary" : "registration of 'V8' names an aspect but no 'as' interface - 'with aspect of' follows 'register X() as Interface', so give 'as' too",
"wouldBeDiagnostics" : [ ],
"written" : false
}
Application no registration error
Request
{
"dryRun" : true,
"file" : "main.ek9",
"name" : "EmptyApp"
}
Response
{
"conflicts" : [ ],
"edits" : [ ],
"error" : {
"message" : "an application requires at least one registration in 'registrations' — an application IS its DI registrations and a bare shell does not compile"
},
"meta" : {
"serverMs" : "<timing>"
},
"status" : "error",
"summary" : "an application requires at least one registration in 'registrations' — an application IS its DI registrations and a bare shell does not compile",
"wouldBeDiagnostics" : [ ],
"written" : false
}
Application dry run ready
Request
{
"dryRun" : true,
"file" : "main.ek9",
"name" : "DemoApp",
"registrations" : [ {
"as" : "Engine",
"component" : "V8"
} ]
}
Response
{
"conflicts" : [ ],
"edits" : [ {
"after" : "\n defines application\n DemoApp\n register V8() as Engine\n",
"endLine" : 15,
"file" : "main.ek9",
"startLine" : 15,
"type" : "insert"
} ],
"meta" : {
"serverMs" : "<timing>"
},
"risk" : {
"crossesModuleBoundary" : false,
"estimatedSeverity" : "trivial",
"fileCount" : 1,
"lineCount" : 1,
"touchesPublicApi" : false,
"touchesTests" : false
},
"status" : "ready",
"summary" : "Scaffold application DemoApp",
"workspaceHash" : "<workspace-hash>",
"wouldBeDiagnostics" : [ ],
...
Cut short here: 2 more lines. The whole recorded call.
See also
- Show me in the IDE: Chapter 34: a contract, two implementations and two applications, built
- Show me in the IDE: Chapter 34: the seams that make a game testable, built
- Show me in the IDE: Chapter 35: two aspects on one component, built
- Show me in the IDE: Chapter 35: a timing aspect and its own data, built
- Show me in the IDE: Chapter 35: an aspect around a method that throws, built
- Show me in the IDE: Chapter 35: an aspect that counts calls, built
- Show me in the IDE: Chapter 36: a service and its HTTP client in one process, built
- Show me in the IDE: Chapter 37: the smallest web service, built
- Show me in the IDE: Chapter 37: two routes that could both match, built
- Show me in the IDE: Chapter 37: a status decided late, built
- Show me in the IDE: Chapter 39: three kinds of test, one runner, built
- Show me in the IDE: An application and its test double
- Show me in the IDE: An aspect around a component
- Show me in the IDE: A web service, built and served