Function diSet

  • Override Dependency Injection friendly function with another one

    Should be called within diInit callback

    Type Parameters

    • T extends Function

    Parameters

    • dep: T
    • value: T

    Returns void

    const fun = di(x => x + 1)
    fun(1) // 2
    diSet(fun, x => x + 2)
    fun(1) // 3

    DiNotInitializedError if called outside of diInit callback

  • Register any value inside Dependency Injection container by unique string literal

    Can be extracted later using diDep

    Should be called within diInit callback

    Parameters

    • dep: string
    • value: unknown

    Returns void

    type User = {
    login: string;
    roles: string[];
    }
    const user: User = {login: 'root', roles: ['admin']}
    diSet('user', user)
    diDep<User>('user') // {login: 'root', roles: ['admin']}

    DiNotInitializedError if called outside of diInit callback