0.3.2 • Published 4 years ago

@coremod/ioc v0.3.2

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

Table of contents

Installation

First, install the Coremod CLI globally.

npm install -g ts-node coremod

Next, add Coremod to your project and install all peer dependencies.

npm install -S coremod
coremod --help

Modules

Install the Official Coremod modules:

npm i -S @coremod/ioc
npm i -S @coremod/express
npm i -S @coremod/public
npm i -S @coremod/logger
npm i -S @coremod/typeorm
npm i -S @coremod/authentication

Configuration

Create a file called coremod.config.ts. The configuration uses the Babel configuration pattern.

import { CoremodConfiguration } from 'coremod';

import { module as IOCModule } from '@coremod/ioc';
import { module as LoggerModule } from '@coremod/logger';
import { module as ExpressModule } from '@coremod/express';
import { module as PublicModule } from '@coremod/public';
import { module as TypeORMModule } from '@coremod/typeorm';
import { module as AuthenticationModule } from '@coremod/authentication';

export const configuration: CoremodConfiguration = {
    modules: [
        IOCModule,
        LoggerModule,
        ExpressModule,
        [PublicModule, {
            favicon: false
        }],
        TypeORMModule,
        [AuthenticationModule, {
            configuration: {
                jwt: {
                    secretOrKey: '##helloworld1234##'
                }
            }
        }]
    ]
};

Writing a module

Create a local module in modules/local-module and add the following starter code to modules/local-module/index.ts:

import {
    CoremodModule,
    CoremodModuleOptions,
    CoremodModuleRuntimeConfiguration,
    CoremodModuleRuntimeContext,
    CoremodModuleRuntime,
    CoremodModuleOptions,
    CoremodModuleRuntimeConfiguration, 
    env
} from 'coremod';

export const configuration: CoremodModuleRuntimeConfiguration = {
    host: env.get('HOST', 'localhost'),
    port: env.get('PORT', '3030')
};

export const runtime: CoremodModuleRuntime = (context: CoremodModuleRuntimeContext, configuration: CoremodModuleRuntimeConfiguration, moduleOptions: CoremodModuleOptions) => {
    console.log(context, configuration, moduleOptions)
};

export const moduleOptions: CoremodModuleOptions = {
    something: true
};

export const module: CoremodModule = {
    namespace: 'local',
    moduleOptions,
    configuration,
    runtime,
};

export default module;

Modules have the following format:

  • namespace is used to wrap the runtime configuration
  • moduleOptions is used to set the module initialization options, which shouldn't be available to other modules
  • configuration is merged to the configuration object passed to the runtime function
  • runtime function used to add and modify the functionality of the application. Gets access to configuration object and context (the object that stores instances such as the Express application or TypeORM connection)

Next, add it to your coremod.config.ts file:

import { resolve } from 'path';
import { CoremodConfiguration } from 'coremod';
import { module as LocalModule } from './modules/local-module';

export const configuration: CoremodConfiguration = {
    modules: [
        [LocalModule, {
            something: true,
            configuration: {
                host: '3031'
            }
        }]
    ]
}

Bugs and feature requests

Have a bug or a feature request? Please first search for existing and closed issues. If your problem or idea is not addressed yet, please open a new issue.

Versioning

For increased transparency and backward compatibility, Coremod is maintained under the Semantic Versioning guidelines.

Creators

Alex Grozav

Copyright and license

Code copyright 2020 Coremod Authors. Code released under the MIT License.

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.23

4 years ago

0.2.22

4 years ago

0.2.21

4 years ago

0.2.17

4 years ago

0.2.16

4 years ago