refactor(core): separate reflective injector from Injector interface
BREAKING CHANGE: - Injector was renamed into `ReflectiveInjector`, as `Injector` is only an abstract class with one method on it - `Injector.getOptional()` was changed into `Injector.get(token, notFoundValue)` to make implementing injectors simpler - `ViewContainerRef.createComponent` now takes an `Injector` instead of `ResolvedProviders`. If a reflective injector should be used, create one before calling this method. (e.g. via `ReflectiveInjector.resolveAndCreate(…)`.
This commit is contained in:
@ -19,4 +19,4 @@ export {MeasureValues} from './src/measure_values';
|
||||
export {MultiMetric} from './src/metric/multi_metric';
|
||||
export {MultiReporter} from './src/reporter/multi_reporter';
|
||||
|
||||
export {bind, provide, Injector, OpaqueToken} from 'angular2/src/core/di';
|
||||
export {bind, provide, Injector, ReflectiveInjector, OpaqueToken} from 'angular2/src/core/di';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {Injector, bind, provide, Provider} from 'angular2/src/core/di';
|
||||
import {Injector, bind, provide, Provider, ReflectiveInjector} from 'angular2/src/core/di';
|
||||
import {isPresent, isBlank} from 'angular2/src/facade/lang';
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
|
||||
@ -52,7 +52,7 @@ export class Runner {
|
||||
sampleBindings.push(bindings);
|
||||
}
|
||||
|
||||
var inj = Injector.resolveAndCreate(sampleBindings);
|
||||
var inj = ReflectiveInjector.resolveAndCreate(sampleBindings);
|
||||
var adapter = inj.get(WebDriverAdapter);
|
||||
|
||||
return PromiseWrapper
|
||||
@ -66,7 +66,7 @@ export class Runner {
|
||||
// Only WebDriverAdapter is reused.
|
||||
// TODO vsavkin consider changing it when toAsyncFactory is added back or when child
|
||||
// injectors are handled better.
|
||||
var injector = Injector.resolveAndCreate([
|
||||
var injector = ReflectiveInjector.resolveAndCreate([
|
||||
sampleBindings,
|
||||
bind(Options.CAPABILITIES).toValue(capabilities),
|
||||
bind(Options.USER_AGENT).toValue(userAgent),
|
||||
|
@ -14,14 +14,14 @@ import {
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
|
||||
import {Metric, MultiMetric, bind, provide, Injector} from 'benchpress/common';
|
||||
import {Metric, MultiMetric, bind, provide, ReflectiveInjector} from 'benchpress/common';
|
||||
|
||||
export function main() {
|
||||
function createMetric(ids: any[]) {
|
||||
var m = Injector.resolveAndCreate([
|
||||
ids.map(id => provide(id, {useValue: new MockMetric(id)})),
|
||||
MultiMetric.createBindings(ids)
|
||||
])
|
||||
var m = ReflectiveInjector.resolveAndCreate([
|
||||
ids.map(id => provide(id, {useValue: new MockMetric(id)})),
|
||||
MultiMetric.createBindings(ids)
|
||||
])
|
||||
.get(MultiMetric);
|
||||
return PromiseWrapper.resolve(m);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import {
|
||||
PerfLogFeatures,
|
||||
bind,
|
||||
provide,
|
||||
Injector,
|
||||
ReflectiveInjector,
|
||||
Options
|
||||
} from 'benchpress/common';
|
||||
|
||||
@ -72,7 +72,7 @@ export function main() {
|
||||
if (isPresent(requestCount)) {
|
||||
bindings.push(bind(Options.REQUEST_COUNT).toValue(requestCount));
|
||||
}
|
||||
return Injector.resolveAndCreate(bindings).get(PerflogMetric);
|
||||
return ReflectiveInjector.resolveAndCreate(bindings).get(PerflogMetric);
|
||||
}
|
||||
|
||||
describe('perflog metric', () => {
|
||||
|
@ -16,7 +16,7 @@ import {
|
||||
Reporter,
|
||||
bind,
|
||||
provide,
|
||||
Injector,
|
||||
ReflectiveInjector,
|
||||
ConsoleReporter,
|
||||
SampleDescription,
|
||||
MeasureValues
|
||||
@ -45,7 +45,7 @@ export function main() {
|
||||
if (isPresent(columnWidth)) {
|
||||
bindings.push(bind(ConsoleReporter.COLUMN_WIDTH).toValue(columnWidth));
|
||||
}
|
||||
reporter = Injector.resolveAndCreate(bindings).get(ConsoleReporter);
|
||||
reporter = ReflectiveInjector.resolveAndCreate(bindings).get(ConsoleReporter);
|
||||
}
|
||||
|
||||
it('should print the sample id, description and table header', () => {
|
||||
|
@ -17,7 +17,7 @@ import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {
|
||||
bind,
|
||||
provide,
|
||||
Injector,
|
||||
ReflectiveInjector,
|
||||
SampleDescription,
|
||||
MeasureValues,
|
||||
Options
|
||||
@ -43,7 +43,7 @@ export function main() {
|
||||
return PromiseWrapper.resolve(null);
|
||||
})
|
||||
];
|
||||
return Injector.resolveAndCreate(bindings).get(JsonFileReporter);
|
||||
return ReflectiveInjector.resolveAndCreate(bindings).get(JsonFileReporter);
|
||||
}
|
||||
|
||||
it('should write all data into a file', inject([AsyncTestCompleter], (async) => {
|
||||
|
@ -14,14 +14,21 @@ import {
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {DateWrapper} from 'angular2/src/facade/lang';
|
||||
|
||||
import {Reporter, MultiReporter, bind, provide, Injector, MeasureValues} from 'benchpress/common';
|
||||
import {
|
||||
Reporter,
|
||||
MultiReporter,
|
||||
bind,
|
||||
provide,
|
||||
ReflectiveInjector,
|
||||
MeasureValues
|
||||
} from 'benchpress/common';
|
||||
|
||||
export function main() {
|
||||
function createReporters(ids: any[]) {
|
||||
var r = Injector.resolveAndCreate([
|
||||
ids.map(id => provide(id, {useValue: new MockReporter(id)})),
|
||||
MultiReporter.createBindings(ids)
|
||||
])
|
||||
var r = ReflectiveInjector.resolveAndCreate([
|
||||
ids.map(id => provide(id, {useValue: new MockReporter(id)})),
|
||||
MultiReporter.createBindings(ids)
|
||||
])
|
||||
.get(MultiReporter);
|
||||
return PromiseWrapper.resolve(r);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import {
|
||||
Validator,
|
||||
bind,
|
||||
provide,
|
||||
ReflectiveInjector,
|
||||
Injector,
|
||||
Metric,
|
||||
Options,
|
||||
@ -28,7 +29,7 @@ import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
|
||||
export function main() {
|
||||
describe('runner', () => {
|
||||
var injector: Injector;
|
||||
var injector: ReflectiveInjector;
|
||||
var runner;
|
||||
|
||||
function createRunner(defaultBindings = null): Runner {
|
||||
|
@ -22,7 +22,7 @@ import {
|
||||
Reporter,
|
||||
bind,
|
||||
provide,
|
||||
Injector,
|
||||
ReflectiveInjector,
|
||||
Options,
|
||||
MeasureValues
|
||||
} from 'benchpress/common';
|
||||
@ -65,7 +65,7 @@ export function main() {
|
||||
bindings.push(bind(Options.PREPARE).toValue(prepare));
|
||||
}
|
||||
|
||||
sampler = Injector.resolveAndCreate(bindings).get(Sampler);
|
||||
sampler = ReflectiveInjector.resolveAndCreate(bindings).get(Sampler);
|
||||
}
|
||||
|
||||
it('should call the prepare and execute callbacks using WebDriverAdapter.waitFor',
|
||||
|
@ -14,7 +14,7 @@ import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {
|
||||
Validator,
|
||||
RegressionSlopeValidator,
|
||||
Injector,
|
||||
ReflectiveInjector,
|
||||
bind,
|
||||
provide,
|
||||
MeasureValues
|
||||
@ -25,11 +25,11 @@ export function main() {
|
||||
var validator;
|
||||
|
||||
function createValidator({size, metric}) {
|
||||
validator = Injector.resolveAndCreate([
|
||||
RegressionSlopeValidator.BINDINGS,
|
||||
bind(RegressionSlopeValidator.METRIC).toValue(metric),
|
||||
bind(RegressionSlopeValidator.SAMPLE_SIZE).toValue(size)
|
||||
])
|
||||
validator = ReflectiveInjector.resolveAndCreate([
|
||||
RegressionSlopeValidator.BINDINGS,
|
||||
bind(RegressionSlopeValidator.METRIC).toValue(metric),
|
||||
bind(RegressionSlopeValidator.SAMPLE_SIZE).toValue(size)
|
||||
])
|
||||
.get(RegressionSlopeValidator);
|
||||
}
|
||||
|
||||
|
@ -11,17 +11,25 @@ import {
|
||||
import {Date, DateWrapper} from 'angular2/src/facade/lang';
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
|
||||
import {Validator, SizeValidator, Injector, bind, provide, MeasureValues} from 'benchpress/common';
|
||||
import {
|
||||
Validator,
|
||||
SizeValidator,
|
||||
ReflectiveInjector,
|
||||
bind,
|
||||
provide,
|
||||
MeasureValues
|
||||
} from 'benchpress/common';
|
||||
|
||||
export function main() {
|
||||
describe('size validator', () => {
|
||||
var validator;
|
||||
|
||||
function createValidator(size) {
|
||||
validator =
|
||||
Injector.resolveAndCreate(
|
||||
[SizeValidator.BINDINGS, bind(SizeValidator.SAMPLE_SIZE).toValue(size)])
|
||||
.get(SizeValidator);
|
||||
validator = ReflectiveInjector.resolveAndCreate([
|
||||
SizeValidator.BINDINGS,
|
||||
bind(SizeValidator.SAMPLE_SIZE).toValue(size)
|
||||
])
|
||||
.get(SizeValidator);
|
||||
}
|
||||
|
||||
it('should return sampleSize as description', () => {
|
||||
|
@ -14,16 +14,16 @@ import {
|
||||
import {isPresent, StringWrapper} from 'angular2/src/facade/lang';
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
|
||||
import {WebDriverExtension, bind, provide, Injector, Options} from 'benchpress/common';
|
||||
import {WebDriverExtension, bind, provide, ReflectiveInjector, Options} from 'benchpress/common';
|
||||
|
||||
export function main() {
|
||||
function createExtension(ids: any[], caps) {
|
||||
return PromiseWrapper.wrap(() => {
|
||||
return Injector.resolveAndCreate([
|
||||
ids.map(id => provide(id, {useValue: new MockExtension(id)})),
|
||||
bind(Options.CAPABILITIES).toValue(caps),
|
||||
WebDriverExtension.bindTo(ids)
|
||||
])
|
||||
return ReflectiveInjector.resolveAndCreate([
|
||||
ids.map(id => provide(id, {useValue: new MockExtension(id)})),
|
||||
bind(Options.CAPABILITIES).toValue(caps),
|
||||
WebDriverExtension.bindTo(ids)
|
||||
])
|
||||
.get(WebDriverExtension);
|
||||
});
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import {
|
||||
WebDriverExtension,
|
||||
ChromeDriverExtension,
|
||||
WebDriverAdapter,
|
||||
Injector,
|
||||
ReflectiveInjector,
|
||||
bind,
|
||||
provide,
|
||||
Options
|
||||
@ -57,13 +57,14 @@ export function main() {
|
||||
userAgent = CHROME44_USER_AGENT;
|
||||
}
|
||||
log = [];
|
||||
extension = Injector.resolveAndCreate([
|
||||
ChromeDriverExtension.BINDINGS,
|
||||
bind(WebDriverAdapter)
|
||||
.toValue(new MockDriverAdapter(log, perfRecords, messageMethod)),
|
||||
bind(Options.USER_AGENT).toValue(userAgent)
|
||||
])
|
||||
.get(ChromeDriverExtension);
|
||||
extension =
|
||||
ReflectiveInjector.resolveAndCreate([
|
||||
ChromeDriverExtension.BINDINGS,
|
||||
bind(WebDriverAdapter)
|
||||
.toValue(new MockDriverAdapter(log, perfRecords, messageMethod)),
|
||||
bind(Options.USER_AGENT).toValue(userAgent)
|
||||
])
|
||||
.get(ChromeDriverExtension);
|
||||
return extension;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ import {
|
||||
WebDriverExtension,
|
||||
IOsDriverExtension,
|
||||
WebDriverAdapter,
|
||||
Injector,
|
||||
ReflectiveInjector,
|
||||
bind,
|
||||
provide
|
||||
} from 'benchpress/common';
|
||||
@ -37,12 +37,12 @@ export function main() {
|
||||
perfRecords = [];
|
||||
}
|
||||
log = [];
|
||||
extension =
|
||||
Injector.resolveAndCreate([
|
||||
IOsDriverExtension.BINDINGS,
|
||||
provide(WebDriverAdapter, {useValue: new MockDriverAdapter(log, perfRecords)})
|
||||
])
|
||||
.get(IOsDriverExtension);
|
||||
extension = ReflectiveInjector.resolveAndCreate([
|
||||
IOsDriverExtension.BINDINGS,
|
||||
provide(WebDriverAdapter,
|
||||
{useValue: new MockDriverAdapter(log, perfRecords)})
|
||||
])
|
||||
.get(IOsDriverExtension);
|
||||
return extension;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user