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.

Category: Editor · Compare: New Application / DI Container

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

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' flat list renders 'with aspect of A, B' for AOP, 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

ArgumentTypeRequiredWhat it is
filestringyesWorkspace-relative path to the .ek9 module file the application is appended to (the 'defines application' block is created if absent).
namestringyesApplication name (PascalCase), e.g. 'DemoApp'.
registrationsarray of objectDI 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' 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.

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.