-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(inversify): upgrade inversify to the latest version
Also add some quality improvements with tests and mutation testing.
- Loading branch information
Showing
24 changed files
with
511 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# 2 space indentation | ||
[{*.ts,*.js,*.json}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
# Operating system related files | ||
*~ | ||
.fuse_hidden* | ||
.directory | ||
.Trash-* | ||
/.idea | ||
/node_modules/ | ||
/env.json | ||
|
||
/**/*.js | ||
# Intellij ide files | ||
.idea | ||
|
||
# Ignore environment file, use env.json.example instead | ||
config/env.json | ||
|
||
# Ignore package manager files | ||
node_modules/ | ||
package-lock.json | ||
|
||
# Ignore everything related to test output | ||
reports | ||
.nyc_output | ||
|
||
# Ignore javascript files, sourcemaps and type declarations | ||
src/**/*.js | ||
test/**/*.js | ||
src/**/*.d.ts | ||
test/**/*.d.ts | ||
src/**/*.js.map | ||
test/**/*.js.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"files": { | ||
"exclude": { | ||
".git": "", | ||
".tscache": "", | ||
"**/*.d.ts": true, | ||
"**/*.js": { | ||
"when": "$(basename).ts" | ||
}, | ||
"**/*.map": { | ||
"when": "$(basename)" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
interface Environment { | ||
appName: string, | ||
port: Number, | ||
loadPaths: Array<string> | ||
} | ||
appName: string; | ||
port: number; | ||
loadPaths: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
const TYPES = { | ||
Environment: Symbol("Environment"), | ||
Logger: Symbol("Logger") | ||
Environment: Symbol('Environment'), | ||
Logger: Symbol('Logger'), | ||
Console: Symbol('Console') | ||
}; | ||
|
||
export default TYPES; | ||
export default TYPES; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,56 @@ | ||
import "reflect-metadata"; | ||
import { Container, inject } from 'inversify'; | ||
import { autoProvide, makeFluentProvideDecorator } from 'inversify-binding-decorators'; | ||
import { Container, ContainerModule } from 'inversify'; | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import 'reflect-metadata'; | ||
|
||
let container = new Container(); | ||
export default class IocContext { | ||
private static METADATA_PROVIDE_KEY = 'inversify-binding-decorators:provide'; | ||
private static ALLOWED_EXTENSIONS = ['.js']; | ||
|
||
let provide = makeFluentProvideDecorator(container); | ||
public constructor( | ||
private projectRoot: string, | ||
/* istanbul ignore next */ | ||
private loader: NodeRequire = require, | ||
/* istanbul ignore next */ | ||
private container: Container = new Container(), | ||
/* istanbul ignore next */ | ||
private reflect: any = Reflect | ||
) { } | ||
|
||
export { container, autoProvide, provide, inject }; | ||
public componentScan(contextPaths: string[]) { | ||
contextPaths.forEach(contextPath => this.readDir(path.join(this.projectRoot, contextPath))); | ||
|
||
this.container.load(this.getAnnotatedDependencies()); | ||
} | ||
|
||
public getContainer() { | ||
return this.container; | ||
} | ||
|
||
private readDir(dir: string) { | ||
fs.readdirSync(dir).forEach((entity) => { | ||
this.processEntity(path.join(dir, entity)); | ||
}); | ||
} | ||
|
||
private processEntity(entity: string) { | ||
if (fs.statSync(entity).isDirectory()) { | ||
this.readDir(entity); | ||
} else { | ||
this.loadFile(entity); | ||
} | ||
} | ||
|
||
private loadFile(filePath: string) { | ||
if (IocContext.ALLOWED_EXTENSIONS.indexOf(path.extname(filePath)) !== -1) { | ||
this.loader(filePath); | ||
} | ||
} | ||
|
||
private getAnnotatedDependencies() { | ||
return new ContainerModule(bind => { | ||
const provideMetadata: any[] = this.reflect.getMetadata(IocContext.METADATA_PROVIDE_KEY, this.reflect) || []; | ||
provideMetadata.map(metadata => metadata.constraint(bind, metadata.implementationType)); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { fluentProvide, provide } from 'inversify-binding-decorators'; | ||
import { interfaces, inject } from 'inversify'; | ||
|
||
const provideSingleton = (identifier: interfaces.ServiceIdentifier<any>) => { | ||
return fluentProvide(identifier).inSingletonScope().done(); | ||
}; | ||
|
||
export { provideSingleton, fluentProvide, inject, provide }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
interface Logger { | ||
log(message: string); | ||
log(message: string): void; | ||
} | ||
|
||
export default Logger; | ||
export default Logger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
import TYPES from "../../constants/types"; | ||
import Logger from "./logger"; | ||
import { provide, inject } from "../../ioc/ioc"; | ||
import TYPES from '../../constants/types'; | ||
import Logger from './logger'; | ||
import { inject, provideSingleton } from '../../ioc/iocUtils'; | ||
import 'reflect-metadata'; | ||
|
||
@provide(TYPES.Logger).done() | ||
/* tslint:disable:no-console */ | ||
@provideSingleton(TYPES.Logger) | ||
class LoggerImpl implements Logger { | ||
private _appName: string; | ||
private appName: string; | ||
private consoleRef: any; | ||
|
||
public constructor(@inject(TYPES.Environment) environment: any) | ||
{ | ||
this._appName = environment.appName; | ||
} | ||
public constructor(@inject(TYPES.Environment) environment: any, @inject(TYPES.Console) consoleRef: any) { | ||
this.consoleRef = consoleRef || console; | ||
this.appName = environment.appName; | ||
} | ||
|
||
public log(message: string) { | ||
console.log(this._appName + " says: " + message); | ||
} | ||
public log(message: string) { | ||
this.consoleRef.log(this.appName + ' says: ' + message); | ||
} | ||
} | ||
|
||
export default LoggerImpl; | ||
export default LoggerImpl; |
Oops, something went wrong.