@blockr/blockr-data-access
v2.1.0-18
Published
Data access layer for Blockr
Downloads
13
Readme
blockr-data-access TypeScript
|CI|SonarQube|Version| |:-:|:-:|:-:| ||||
The data access layer can be consumed either by dependency injection
or normal construction.
Dependency injection
This library uses inversify-js
as its dependency injection library. This means the consuming project is required to do the same. The data access layer has two dependencies: DataSource
and Configuration
that either need to be injected or constructed.
|Name|Type|
|-|-|
|DataSource
|Enum
|
|Configuration
|IClientConfiguration
|
Example:
container
DIContainer.bind<DataAccessLayer>(DataAccessLayer).toSelf().inTransientScope();
DIContainer.bind<DataSource>("DataSource").toConstantValue(DataSource.MONGO_DB);
DIContainer.bind<IClientConfiguration>("Configuration")
.toConstantValue(new MongoDbConfiguration("connection string", "database"));
consumer (typically a service)
class MainService {
private dataAccessLayer: DataAccessLayer;
constructor(@inject(DataAccessLayer) dataAccessLayer: DataAccessLayer) {
this.dataAccessLayer = dataAccessLayer;
}
}
Normal construction
Example:
consumer (typically a service)
class MainService {
private dataAccessLayer: DataAccessLayer;
constructor() {
this.dataAccessLayer = new DataAccessLayer(
DataSource.MONGO_DB,
new MongoDbConfiguration("connection string", "database")
);
}
}