Class Connector<C, T>Abstract

Description

Connector interface

Features:

  • Common interface for all connectors

Example

import { Connector, IConnector } from '../..';
import { inject, container, Types, Core } from '@biorate/inversion';
import { IConfig, Config } from '@biorate/config';

export class Connection {
public name: string;

public constructor(name: string) {
this.name = name;
}
}

export class TestConnector extends Connector<{ name: string }, Connection> {
protected namespace = 'TestConnector';

protected async connect(config) {
return new Connection(config.name);
}
}

export class Root extends Core() {
@inject(TestConnector) public connector: IConnector<{ name: string }, Connection>;
}

container.bind(Types.Config).to(Config).inSingletonScope();
container.bind(TestConnector).toSelf().inSingletonScope();
container.bind(Root).toSelf().inSingletonScope();

container.get<IConfig>(Types.Config).merge({
TestConnector: [{ name: 'test-connection' }],
});

(async () => {
const root = container.get<Root>(Root);
await root.$run();
console.log(root.connector.connection('test-connection')); // Connection { name: 'test-connection' }
})();

Type Parameters

Hierarchy

Implements

Constructors

Properties

#connections: Map<string, T> = ...

Description

Private connections storage

#current: T = undefined

Description

Private link to selected (used) connection

config: IConfig

Description

Config dependency

namespace: string

Description

Namespace path for fetching configuration

Accessors

Methods

Generated using TypeDoc