1.4.0 • Published 1 year ago

@11z/core v1.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@11z/core

11z(core) - lighter, easier and maintainable.

Feature ✨

  • Typescript dependency injection ✔

Table of contents

Example

Dependency injection

./di.ts

import { Injectable, Injector, Inject } from '@11z/core'

// Injector service.
@Injectable()
class ExampleService {
    public helloWorld(): string {
        return 'hello world!'
    }
}

// Injector.
class Example {
    constructor(@Inject(ExampleService) private readonly exampleService: ExampleService) {}

    public helloWorld(): string {
        return this.exampleService.helloWorld()
    }
}

// NOTE: Testing purpose.
const example = Injector.get(Example)
console.log(example.helloWorld()) // hello word!

Installation

You need nodeJs install.

# with npm
npm i @11z/core

# installing typescript
1. npm i -D typescript - in this case I'm using npm.
2. npx tsc --init - to create tsconfig.json file.

As we all know, the library uses @decorator without enabling some additional features. Typescript will complain. You need to enable these additional features of Typescript. In the file 'tsconfig.json' Launch these:

{
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
}

That's it. let's get into coding! see example.

Apis

We provide all the Apis that you will need to create a flexible and maintainable application.

@Injectable

The @Injectable() decorator is used to define metadata object.

Example:

./injectable.ts

import { Injectable } from '@11z/core'

@Injectable()
export class ExampleService {}

@Inject

The @Inject() decorator is used to mark parameter as dependency.

Example:

./inject.ts

import { Inject } from '@11z/core'
import { ExampleService } from './injectable'

export class Example {
    constructor(@Inject(ExampleService) private readonly exampleService: ExampleService) {}
}

@Injector

A top-level class used to resolve injector value.

Example:

./injector.ts

import { Injector } from '@11z/core'
import { Example } from './inject'

// Resolve Example injector value.
Injector.get(Example)

Define injector

The defineInjector function is used to define metadata object.

Example:

import { defineInjector } from '@11z/core'

export class Example {}

// Define injector.
defineInjector(Example)

The end

11z - lighter, easier and maintainable.

1.4.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago

0.30.0

1 year ago

0.29.0

1 year ago

0.28.0

1 year ago

0.27.0

1 year ago

0.25.0

1 year ago

0.24.0

1 year ago

0.23.0

1 year ago

0.22.0

1 year ago

0.20.0

1 year ago

0.19.0

1 year ago

0.18.0

1 year ago

0.17.0

1 year ago

0.16.0

1 year ago

0.15.0

1 year ago

0.14.0

1 year ago

0.13.0

1 year ago

0.11.0

1 year ago

0.10.0

1 year ago

0.9.0

1 year ago

0.8.0

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago