1.0.8 • Published 2 years ago

@uon/core v1.0.8

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

UON CORE

A modular application framework with dependency injection. Based on @angular application structure.

Usage

npm i @uon/core

Modules

Application modules are defined with the @Module decorator.

import { Module } from '@uon/core';

@Module({
    imports: [],
    providers: []
})
export class MyModule {}

Providers

Declaring a list of providers make them available to the dependency injector.

Providers are referenced my their token. A token can be any comparable value; however, for code minification purposes, we recommend using either an InjectionToken or a type (class).

There are multiple ways of declaring a provider :

import { Module, InjectionToken } from '@uon/core';

export const MY_VALUE_PROVIDER = 
    new InjectionToken<number>("MY_VALUE_PROVIDER");

@Module({
    imports: [],
    providers: [
        // TypeProvider
        MyService, 

        // ValueProvider
        {
            token: MY_VALUE_PROVIDER,
            value: 1234
        },

        // FactoryProvider
        {
            token: 'MY_FACTORY_PROVIDER',
            factory: (service: MyService) => {
                return service.getStuff();
            },
            deps: [MyService]
        },

        // ClassProvider
        {
            token: MyClass,
            type: MyOverrideClass
        }
    ]
})
export class MyModule {}

TypeProvider & ClassProvider

You can provide a type as a provider. The injector will instanciate the class with DI the first time it is requested.

// MyService.ts
import { Injectable } from '@uon/core';

@Injectable()
export class MyService {

    constructor(private myOtherService: OtherService) {}
}

FactoryProvider

stub

ValueProvider

stub

Application init tasks

If you wish to execute tasks before the application modules are instanciated. You can add a factory provider with the APP_INITIALIZER injection token.

import { Module, APP_INITIALIZER } from '@uon/core';

@Module({
    providers: [
        {
            token: APP_INITIALIZER,
            factory: () => {
                console.log('do stuff');
            },
            multi: true
        }
    ]
})
export class MyModule {}

More coming soon.

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.11.0

4 years ago

0.10.1

5 years ago

0.10.0

5 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago