Skip to content

Dynasty is a typesafe asynchronous dependency injection framework for TypeScript.

License

Notifications You must be signed in to change notification settings

theroyalwhee0/dynasty

Repository files navigation

Dynasty: @theroyalwhee0/dynasty

Description

Dynasty is a typesafe asynchronous dependency injection framework for TypeScript.

Installation

npm install @theroyalwhee0/dynasty

Usage

import Dynasty from '@theroyalwhee0/dynasty';
(async function main() {
    const dyn = new Dynasty();
    const log = dyn.value((...args: unknown[]) => {
        console.log(...args);
    });
    type AppOptions = {
        state: string;
    }
    const options = dyn.record<AppOptions>({
        state: 'FL',
    });
    const table = dyn.once((log) => {
        const table = new Map<string, string>();
        table.set('AL', 'Alabama');
        table.set('CA', 'California');
        table.set('FL', 'Florida');
        table.set('GA', 'Georgia');
        table.set('TX', 'Texas');
        table.set('WA', 'Washington');
        log('TRACE | Table loaded.');
        return table;
    }, [log]);
    const app = dyn.once((log, table, options) => {
        const state = table.get(options.state) ?? 'Unknown';
        log(`INFO  | State: ${state}`);
    }, [log, table, options]);
    await dyn.start(app);
})();

See the examples for more usage demonstrations.

Documentation

Online API Documentation is available.

Documentation can also be found in the 'docs/' folder and generated by running npm run docs.

Differences from Dynasty v1

Dynasty v2 is a complete rewrite of Dynasty v1. The library's approach to dependency injection is completly different. Dynasty v2 does not have a dependency graph. Instead, it helps the developer to manage their dependencies explicitly. Instead of using string-keyed dependencies, Dynasty v2 manages dependencies as normal TypeScript variables. Dynasty v2 is built as an ESModule library.

Links

Legal & License

Copyright 2019-2024 Adam Mill

This library is released under Apache 2 license. See LICENSE for more details.

About

Dynasty is a typesafe asynchronous dependency injection framework for TypeScript.

Topics

Resources

License

Security policy

Stars

Watchers

Forks