defineHostExtension
function defineHostExtension<M extends ExtensionMemberMap>(install: (ctx: HostExtensionContext) => M): HostExtension<M>Defines a first-class host extension. The installer runs once at construction: it composes via the narrow HostExtensionContext and returns the member map to install. Each returned member is typed onto the host straight from the array — one extension can install MANY typed members.
Opts are supplied by the package’s own factory closure (mirroring ASP.NET services.AddX(opts)), so
nothing needs to flow through the framework:
// @flare-ts/drizzleexport function drizzle(opts: DrizzleOptions) { return defineHostExtension((host) => { host.cfg(DRIZZLE_CONFIG); // composition runs once, at construction host.scoped(DatabaseService); return { db: makeQueryApi(opts), // host.db -- typed migrate: () => runMigrations(), // host.migrate() -- typed }; });}
// user app -- referencing `drizzle` forces the runtime import; passing it opts in AND types the members.const host = new FlareHost(node, [drizzle({ url: "..." })]);host.db.query("select 1");host.migrate();Because composition runs once in the installer body (not per member call), passing the extension is the single opt-in: there is no separate activation call.
install (ctx: HostExtensionContext) => M
returns HostExtension<M>
Learn: Host extensions