Skip to content
Beskid Platform specification

Beskid

Jump to a Beskid service

Beskid

Jump to a Beskid service

Native dependency injection - Examples

Platform spec article

Native dependency injection - Examples

Spec standingStandard

Owner
Piotr Mikstacki
Submitter
Piotr Mikstacki
host AppHost(string[] args) : ConsoleHost {
registry {
single AppConfig for Configuration;
single SqlStorage for Storage;
single FileStorage for Storage;
}
startup(Configuration config, Storage[] storages) {
for s in storages { s.Open(config); }
}
}
type StorageAggregator {
inject Configuration configuration;
inject Storage[] storages;
}
unit main(string[] args) {
launch AppHost(args);
}

Lib project (no launch):

host InfraHost : ConsoleHost {
registry {
single SharedLogger for Logger;
}
}

App project:

host AppHost(string[] args) : InfraHost {
registry {
single AppLogger for Logger; // overrides InfraHost Logger
}
startup(Logger logger) { }
}
unit main(string[] args) {
launch AppHost(args);
}

Named scope with init, dispose, and navigation

Section titled “Named scope with init, dispose, and navigation”
host AppHost(string[] args) : ConsoleHost {
registry {
single AppConfiguration for Configuration;
}
scope HttpScope(RequestContext request) {
ScopedDbSession for DbSession;
init(global::Configuration config, DbSession db) {
db.Connect(config, request);
}
dispose(DbSession db) {
db.Close();
}
}
startup(Configuration config) { }
}
type RequestWorker {
inject global::Configuration configuration;
unit Run(RequestContext request) {
with HttpScope(request) {
Process();
}
}
}
registry {
single A for Provider;
single B for Provider;
}
type Consumer {
inject Provider[] providers; // OK — both A and B
// inject Provider p; // E1705 — use array form
}
with HttpScope(request) {
with UnitOfWork(readOnly: false) { Save(); }
}
with HttpScope(request) {
with UnitOfWork(readOnly: true) { Query(); } // second activation — new scoped set
}

Conformance fixtures under compiler/crates/beskid_tests and compiler/crates/beskid_e2e_tests will track the reference implementation as composition analysis lands.