Moved factories logi from container modules to InversifyContainerFacade

This commit is contained in:
sanex3339
2017-05-27 10:44:54 +03:00
parent cf2de98fd8
commit 4304923ce8
9 changed files with 7899 additions and 108 deletions
+7830 -1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -51,12 +51,12 @@
"babel-loader": "7.0.0",
"babel-plugin-array-includes": "2.0.3",
"babel-preset-es2015": "6.24.1",
"chai": "4.0.0-canary.2",
"chai": "4.0.0",
"coveralls": "2.13.1",
"istanbul": "1.1.0-alpha.1",
"mocha": "3.4.2",
"pre-commit": "^1.2.2",
"sinon": "2.3.1",
"sinon": "2.3.2",
"ts-node": "3.0.4",
"tslint": "5.3.2",
"tslint-loader": "3.5.3",
+38
View File
@@ -91,6 +91,44 @@ export class InversifyContainerFacade implements IInversifyContainerFacade {
this.container.load(obfuscatingTransformersModule);
}
/**
* @param serviceIdentifier
* @return {(context:interfaces.Context)=>(bindingName:T)=>U}
*/
public static getFactory <T extends number, U> (
serviceIdentifier: interfaces.ServiceIdentifier<U>
): (context: interfaces.Context) => (bindingName: T) => U {
return (context: interfaces.Context): (bindingName: T) => U => {
return (bindingName: T) => {
return context.container.getNamed<U>(serviceIdentifier, bindingName);
};
};
}
/**
* @param serviceIdentifier
* @return {(context:interfaces.Context)=>(bindingName:T)=>U}
*/
public static getCacheFactory <T extends number, U> (
serviceIdentifier: interfaces.ServiceIdentifier<U>
): (context: interfaces.Context) => (bindingName: T) => U {
return (context: interfaces.Context): (bindingName: T) => U => {
const cache: Map <T, U> = new Map();
return (bindingName: T) => {
if (cache.has(bindingName)) {
return <U>cache.get(bindingName);
}
const object: U = context.container.getNamed<U>(serviceIdentifier, bindingName);
cache.set(bindingName, object);
return object;
};
};
}
/**
* @param serviceIdentifier
* @returns {T}
@@ -1,3 +1,4 @@
import { InversifyContainerFacade } from '../../InversifyContainerFacade';
import { ContainerModule, interfaces } from 'inversify';
import { ServiceIdentifiers } from '../../ServiceIdentifiers';
@@ -163,12 +164,6 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule
// customNodeGroup factory
bind<ICustomNodeGroup>(ServiceIdentifiers.Factory__ICustomNodeGroup)
.toFactory<ICustomNodeGroup>((context: interfaces.Context) => {
return (customNodeGroupName: CustomNodeGroups) => {
return context.container.getNamed<ICustomNodeGroup>(
ServiceIdentifiers.ICustomNodeGroup,
customNodeGroupName
);
};
});
.toFactory<ICustomNodeGroup>(InversifyContainerFacade
.getFactory<CustomNodeGroups, ICustomNodeGroup>(ServiceIdentifiers.ICustomNodeGroup));
});
@@ -1,3 +1,4 @@
import { InversifyContainerFacade } from '../../InversifyContainerFacade';
import { ContainerModule, interfaces } from 'inversify';
import { ServiceIdentifiers } from '../../ServiceIdentifiers';
@@ -28,22 +29,6 @@ export const controlFlowTransformersModule: interfaces.ContainerModule = new Con
.whenTargetNamed(ControlFlowReplacers.StringLiteralControlFlowReplacer);
bind<IControlFlowReplacer>(ServiceIdentifiers.Factory__IControlFlowReplacer)
.toFactory<IControlFlowReplacer>((context: interfaces.Context) => {
const cache: Map <ControlFlowReplacers, IControlFlowReplacer> = new Map();
return (replacerName: ControlFlowReplacers) => {
if (cache.has(replacerName)) {
return <IControlFlowReplacer>cache.get(replacerName);
}
const controlFlowReplacer: IControlFlowReplacer = context.container.getNamed<IControlFlowReplacer>(
ServiceIdentifiers.IControlFlowReplacer,
replacerName
);
cache.set(replacerName, controlFlowReplacer);
return controlFlowReplacer;
};
});
.toFactory<IControlFlowReplacer>(InversifyContainerFacade
.getCacheFactory<ControlFlowReplacers, IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer));
});
@@ -1,3 +1,4 @@
import { InversifyContainerFacade } from '../../InversifyContainerFacade';
import { ContainerModule, interfaces } from 'inversify';
import { ServiceIdentifiers } from '../../ServiceIdentifiers';
@@ -78,23 +79,6 @@ export const nodeTransformersModule: interfaces.ContainerModule = new ContainerM
// node transformers factory
bind<INodeTransformer>(ServiceIdentifiers.Factory__INodeTransformer)
.toFactory<INodeTransformer>((context: interfaces.Context) => {
const cache: Map <NodeTransformers, INodeTransformer> = new Map();
return (nodeTransformerName: NodeTransformers) => {
if (cache.has(nodeTransformerName)) {
return <INodeTransformer>cache.get(nodeTransformerName);
}
const nodeTransformer: INodeTransformer = context.container
.getNamed<INodeTransformer>(
ServiceIdentifiers.INodeTransformer,
nodeTransformerName
);
cache.set(nodeTransformerName, nodeTransformer);
return nodeTransformer;
};
});
.toFactory<INodeTransformer>(InversifyContainerFacade
.getCacheFactory<NodeTransformers, INodeTransformer>(ServiceIdentifiers.INodeTransformer));
});
@@ -1,3 +1,4 @@
import { InversifyContainerFacade } from '../../InversifyContainerFacade';
import { ContainerModule, interfaces } from 'inversify';
import { ServiceIdentifiers } from '../../ServiceIdentifiers';
@@ -33,43 +34,15 @@ export const obfuscatingTransformersModule: interfaces.ContainerModule = new Con
// literal obfuscating replacer factory
bind<IObfuscatingReplacer>(ServiceIdentifiers.Factory__IObfuscatingReplacer)
.toFactory<IObfuscatingReplacer>((context: interfaces.Context) => {
const cache: Map <LiteralObfuscatingReplacers, IObfuscatingReplacer> = new Map();
return (replacerName: LiteralObfuscatingReplacers) => {
if (cache.has(replacerName)) {
return <IObfuscatingReplacer>cache.get(replacerName);
}
const replacer: IObfuscatingReplacer = context.container.getNamed<IObfuscatingReplacer>(
ServiceIdentifiers.IObfuscatingReplacer,
replacerName
);
cache.set(replacerName, replacer);
return replacer;
};
});
.toFactory<IObfuscatingReplacer>(InversifyContainerFacade
.getCacheFactory<LiteralObfuscatingReplacers, IObfuscatingReplacer>(
ServiceIdentifiers.IObfuscatingReplacer
));
// identifier obfuscating replacer factory
bind<IIdentifierObfuscatingReplacer>(ServiceIdentifiers.Factory__IIdentifierObfuscatingReplacer)
.toFactory<IIdentifierObfuscatingReplacer>((context: interfaces.Context) => {
const cache: Map <IdentifierObfuscatingReplacers, IIdentifierObfuscatingReplacer> = new Map();
return (replacerName: IdentifierObfuscatingReplacers) => {
if (cache.has(replacerName)) {
return <IIdentifierObfuscatingReplacer>cache.get(replacerName);
}
const replacer: IIdentifierObfuscatingReplacer = context.container.getNamed<IIdentifierObfuscatingReplacer>(
ServiceIdentifiers.IIdentifierObfuscatingReplacer,
replacerName
);
cache.set(replacerName, replacer);
return replacer;
};
});
.toFactory<IIdentifierObfuscatingReplacer>(InversifyContainerFacade
.getCacheFactory<IdentifierObfuscatingReplacers, IIdentifierObfuscatingReplacer>(
ServiceIdentifiers.IIdentifierObfuscatingReplacer
));
});
@@ -1,3 +1,4 @@
import { InversifyContainerFacade } from '../../InversifyContainerFacade';
import { ContainerModule, interfaces } from 'inversify';
import { ServiceIdentifiers } from '../../ServiceIdentifiers';
@@ -31,22 +32,8 @@ export const stackTraceAnalyzerModule: interfaces.ContainerModule = new Containe
// node transformers factory
bind<ICalleeDataExtractor>(ServiceIdentifiers.Factory__ICalleeDataExtractor)
.toFactory<ICalleeDataExtractor>((context: interfaces.Context) => {
const cache: Map <CalleeDataExtractors, ICalleeDataExtractor> = new Map();
return (calleeDataExtractorName: CalleeDataExtractors) => {
if (cache.has(calleeDataExtractorName)) {
return <ICalleeDataExtractor>cache.get(calleeDataExtractorName);
}
const calleeDataExtractor: ICalleeDataExtractor = context.container.getNamed<ICalleeDataExtractor>(
ServiceIdentifiers.ICalleeDataExtractor,
calleeDataExtractorName
);
cache.set(calleeDataExtractorName, calleeDataExtractor);
return calleeDataExtractor;
};
});
.toFactory<ICalleeDataExtractor>(InversifyContainerFacade
.getCacheFactory<CalleeDataExtractors, ICalleeDataExtractor>(
ServiceIdentifiers.ICalleeDataExtractor
));
});
+6 -6
View File
@@ -819,9 +819,9 @@ center-align@^0.1.1:
align-text "^0.1.3"
lazy-cache "^1.0.3"
chai@4.0.0-canary.2:
version "4.0.0-canary.2"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.0.0-canary.2.tgz#a017f59d3ed2d64795c91a51b5034e41b873da87"
chai@4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.0.0.tgz#f6c989e45a5707d40c54d97ddd7ca89b30a6a06a"
dependencies:
assertion-error "^1.0.1"
check-error "^1.0.1"
@@ -2716,9 +2716,9 @@ signal-exit@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
sinon@2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/sinon/-/sinon-2.3.1.tgz#48c9c758b4d0bb86327486833f1c4298919ce9ee"
sinon@2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/sinon/-/sinon-2.3.2.tgz#c43a9c570f32baac1159505cfeed19108855df89"
dependencies:
diff "^3.1.0"
formatio "1.2.0"