feat(di): provide two ways to create an injector, resolved and unresolved
Add two factory static functions to Injector: resolveAndCreate and fromResolvedBindings. We want to avoid resolution and flattening every time we create a new injector. This commit allows the user to cache resolved bindings and reuse them.
This commit is contained in:
@ -50,7 +50,7 @@ export class Runner {
|
||||
if (isPresent(bindings)) {
|
||||
ListWrapper.push(sampleBindings, bindings);
|
||||
}
|
||||
return new Injector(sampleBindings).asyncGet(Sampler)
|
||||
return Injector.resolveAndCreate(sampleBindings).asyncGet(Sampler)
|
||||
.then( (sampler) => sampler.sample() );
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import { Metric, MultiMetric, bind, Injector } from 'benchpress/common';
|
||||
|
||||
export function main() {
|
||||
function createMetric(ids) {
|
||||
return new Injector([
|
||||
return Injector.resolveAndCreate([
|
||||
ListWrapper.map(ids, (id) => bind(id).toValue(new MockMetric(id)) ),
|
||||
MultiMetric.createBindings(ids)
|
||||
]).asyncGet(MultiMetric);
|
||||
|
@ -45,7 +45,7 @@ export function main() {
|
||||
}),
|
||||
bind(WebDriverExtension).toValue(new MockDriverExtension(perfLogs, commandLog, perfLogFeatures))
|
||||
];
|
||||
return new Injector(bindings).get(PerflogMetric);
|
||||
return Injector.resolveAndCreate(bindings).get(PerflogMetric);
|
||||
}
|
||||
|
||||
describe('perflog metric', () => {
|
||||
|
@ -29,7 +29,7 @@ export function main() {
|
||||
if (isPresent(columnWidth)) {
|
||||
ListWrapper.push(bindings, bind(ConsoleReporter.COLUMN_WIDTH).toValue(columnWidth));
|
||||
}
|
||||
reporter = new Injector(bindings).get(ConsoleReporter);
|
||||
reporter = Injector.resolveAndCreate(bindings).get(ConsoleReporter);
|
||||
}
|
||||
|
||||
it('should print the sample id, description and table header', () => {
|
||||
|
@ -42,7 +42,7 @@ export function main() {
|
||||
return PromiseWrapper.resolve(null);
|
||||
})
|
||||
];
|
||||
return new Injector(bindings).get(JsonFileReporter);
|
||||
return Injector.resolveAndCreate(bindings).get(JsonFileReporter);
|
||||
}
|
||||
|
||||
it('should write all data into a file', inject([AsyncTestCompleter], (async) => {
|
||||
|
@ -19,7 +19,7 @@ import { Reporter, MultiReporter, bind, Injector, MeasureValues } from 'benchpre
|
||||
|
||||
export function main() {
|
||||
function createReporters(ids) {
|
||||
return new Injector([
|
||||
return Injector.resolveAndCreate([
|
||||
ListWrapper.map(ids, (id) => bind(id).toValue(new MockReporter(id)) ),
|
||||
MultiReporter.createBindings(ids)
|
||||
]).asyncGet(MultiReporter);
|
||||
|
@ -68,7 +68,7 @@ export function main() {
|
||||
ListWrapper.push(bindings, bind(Options.FORCE_GC).toValue(forceGc));
|
||||
}
|
||||
|
||||
sampler = new Injector(bindings).get(Sampler);
|
||||
sampler = Injector.resolveAndCreate(bindings).get(Sampler);
|
||||
}
|
||||
|
||||
it('should call the prepare and execute callbacks using WebDriverAdapter.waitFor', inject([AsyncTestCompleter], (async) => {
|
||||
|
@ -11,7 +11,7 @@ export function main() {
|
||||
var validator;
|
||||
|
||||
function createValidator({size, metric}) {
|
||||
validator = new Injector([
|
||||
validator = Injector.resolveAndCreate([
|
||||
RegressionSlopeValidator.BINDINGS,
|
||||
bind(RegressionSlopeValidator.METRIC).toValue(metric),
|
||||
bind(RegressionSlopeValidator.SAMPLE_SIZE).toValue(size)
|
||||
|
@ -11,7 +11,7 @@ export function main() {
|
||||
var validator;
|
||||
|
||||
function createValidator(size) {
|
||||
validator = new Injector([
|
||||
validator = Injector.resolveAndCreate([
|
||||
SizeValidator.BINDINGS,
|
||||
bind(SizeValidator.SAMPLE_SIZE).toValue(size)
|
||||
]).get(SizeValidator);
|
||||
|
@ -19,7 +19,7 @@ import { WebDriverExtension, bind, Injector, Options } from 'benchpress/common';
|
||||
|
||||
export function main() {
|
||||
function createExtension(ids, caps) {
|
||||
return new Injector([
|
||||
return Injector.resolveAndCreate([
|
||||
ListWrapper.map(ids, (id) => bind(id).toValue(new MockExtension(id)) ),
|
||||
bind(Options.CAPABILITIES).toValue(caps),
|
||||
WebDriverExtension.bindTo(ids)
|
||||
|
@ -38,7 +38,7 @@ export function main() {
|
||||
perfRecords = [];
|
||||
}
|
||||
log = [];
|
||||
extension = new Injector([
|
||||
extension = Injector.resolveAndCreate([
|
||||
ChromeDriverExtension.BINDINGS,
|
||||
bind(WebDriverAdapter).toValue(new MockDriverAdapter(log, perfRecords, messageMethod))
|
||||
]).get(ChromeDriverExtension);
|
||||
|
@ -34,7 +34,7 @@ export function main() {
|
||||
perfRecords = [];
|
||||
}
|
||||
log = [];
|
||||
extension = new Injector([
|
||||
extension = Injector.resolveAndCreate([
|
||||
IOsDriverExtension.BINDINGS,
|
||||
bind(WebDriverAdapter).toValue(new MockDriverAdapter(log, perfRecords))
|
||||
]).get(IOsDriverExtension);
|
||||
|
Reference in New Issue
Block a user