Skip to content

Commit f567e99

Browse files
committed
chore(di): Update the Module.bind(toFactory) to the new DI 2.0.0 format
1 parent a652680 commit f567e99

15 files changed

+37
-32
lines changed

benchmark/web/tree.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ main() {
254254
..bind(NgFreeTree)
255255
..bind(NgFreeTreeScoped)
256256
..bind(NgFreeTreeClass)
257-
..bind(ScopeDigestTTL, toFactory: (_) => new ScopeDigestTTL.value(15))
257+
..bind(ScopeDigestTTL, toFactory: () => new ScopeDigestTTL.value(15), inject: [])
258258
..bind(CompilerConfig, toValue: new CompilerConfig.withOptions(elementProbeEnabled: false));
259259

260260
var injector = applicationFactory().addModule(module).run();

bin/parser_generator_for_spec.dart

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ import 'dart:io' as io;
22

33
import 'package:di/di.dart';
44
import 'package:di/dynamic_injector.dart';
5+
import 'package:angular/cache/module.dart';
6+
import 'package:angular/core/parser/lexer.dart';
57
import 'package:angular/core/parser/parser.dart';
68
import 'package:angular/tools/parser_getter_setter/generator.dart';
79

810
main(arguments) {
9-
Module module = new Module()..bind(Parser, toFactory: (i) => i.get(DynamicParser));
10-
module.bind(ParserBackend, toFactory: (i) => i.get(DartGetterSetterGen));
11+
Module module = new Module()
12+
..bind(Lexer)
13+
..bind(ParserGetterSetter)
14+
..bind(Parser, toImplementation: DynamicParser)
15+
..install(new CacheModule());
16+
module.bind(ParserBackend, toImplementation: DartGetterSetterGen);
1117
Injector injector = new DynamicInjector(modules: [module],
12-
allowImplicitInjection: true);
18+
allowImplicitInjection: true);
1319

1420
// List generated using:
1521
// node node_modules/karma/bin/karma run | grep -Eo ":XNAY:.*:XNAY:" | sed -e 's/:XNAY://g' | sed -e "s/^/'/" | sed -e "s/$/',/" | sort | uniq > missing_expressions

lib/application.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ abstract class Application {
152152
modules.add(ngModule);
153153
ngModule..bind(VmTurnZone, toValue: zone)
154154
..bind(Application, toValue: this)
155-
..bind(dom.Node, toFactory: (i) => i.getByKey(new Key(Application)).element);
155+
..bind(dom.Node, toFactory: (Application app) => app.element, inject: [Application]);
156156
}
157157

158158
/**

lib/core/module_internal.dart

+5-7
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,19 @@ class CoreModule extends Module {
3535
CoreModule() {
3636
bind(ScopeDigestTTL);
3737

38-
bind(MetadataExtractor);
3938
bind(ExceptionHandler);
4039
bind(FormatterMap);
4140
bind(Interpolate);
4241
bind(RootScope);
43-
bind(Scope, toFactory: (injector) => injector.getByKey(ROOT_SCOPE_KEY));
44-
bind(ClosureMap, toFactory: (_) => throw "Must provide dynamic/static ClosureMap.");
42+
bind(Scope, inject: [RootScope]);
43+
bind(ClosureMap, toFactory: () => throw "Must provide dynamic/static ClosureMap.", inject: []);
4544
bind(ScopeStats);
4645
bind(ScopeStatsEmitter);
47-
bind(ScopeStatsConfig, toFactory: (i) => new ScopeStatsConfig());
46+
bind(ScopeStatsConfig);
4847
bind(Object, toValue: {}); // RootScope context
49-
bind(VmTurnZone);
5048

51-
bind(Parser, toFactory: (i) => i.get(DynamicParser));
52-
bind(ParserBackend, toFactory: (i) => i.get(DynamicParserBackend));
49+
bind(Parser, inject: [DynamicParser]);
50+
bind(ParserBackend, inject: [DynamicParserBackend]);
5351
bind(DynamicParser);
5452
bind(DynamicParserBackend);
5553
bind(Lexer);

lib/core/scope.dart

+1
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ class ScopeStatsEmitter {
532532
* ScopeStatsConfig is used to modify behavior of [ScopeStats]. You can use this
533533
* object to modify behavior at runtime too.
534534
*/
535+
@Injectable()
535536
class ScopeStatsConfig {
536537
var emit = false;
537538

lib/core_dom/common.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class DirectiveRef {
4141
*/
4242
Injector forceNewDirectivesAndFormatters(Injector injector, List<Module> modules) {
4343
modules.add(new Module()
44-
..bind(Scope, toFactory: (i) {
44+
..bind(Scope, toFactory: (Injector i) {
4545
var scope = i.parent.getByKey(SCOPE_KEY);
4646
return scope.createChild(new PrototypeMap(scope.context));
47-
}));
47+
}, inject: [Injector]));
4848

4949
return injector.createChild(modules,
5050
forceNewInstances: [DirectiveMap, FormatterMap]);

lib/core_dom/module_internal.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ class CoreDomModule extends Module {
5757
bind(ElementProbe, toValue: null);
5858

5959
// Default to a unlimited-sized TemplateCache
60-
bind(TemplateCache, toFactory: (i) {
60+
bind(TemplateCache, toFactory: (CacheRegister register) {
6161
var templateCache = new TemplateCache();
62-
i.getByKey(CACHE_REGISTER_KEY).registerCache("TemplateCache", templateCache);
62+
register.registerCache("TemplateCache", templateCache);
6363
return templateCache;
64-
});
64+
}, inject: [CacheRegister]);
6565
bind(dom.NodeTreeSanitizer, toImplementation: NullTreeSanitizer);
6666

6767
bind(TextMustache);
@@ -70,7 +70,7 @@ class CoreDomModule extends Module {
7070
bind(Compiler, toImplementation: TaggingCompiler);
7171
bind(CompilerConfig);
7272

73-
bind(ComponentFactory, toFactory: (i) => i.getByKey(SHADOW_DOM_COMPONENT_FACTORY_KEY));
73+
bind(ComponentFactory, inject: [ShadowDomComponentFactory]);
7474
bind(ShadowDomComponentFactory);
7575
bind(TranscludingComponentFactory);
7676
bind(Content);

lib/directive/module.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class DirectiveModule extends Module {
6868
bind(NgBind, toValue: null);
6969
bind(NgBindTemplate, toValue: null);
7070
bind(NgBindHtml, toValue: null);
71-
bind(dom.NodeValidator, toFactory: (_) => new dom.NodeValidatorBuilder.common());
71+
bind(dom.NodeValidator, toFactory: () => new dom.NodeValidatorBuilder.common(), inject: []);
7272
bind(NgClass, toValue: null);
7373
bind(NgClassOdd, toValue: null);
7474
bind(NgClassEven, toValue: null);

lib/directive/ng_model.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ class NgBindTypeForDateLike {
603603
module: InputDateLike.moduleFactory)
604604
class InputDateLike {
605605
static Module moduleFactory() => new Module()..bind(NgBindTypeForDateLike,
606-
toFactory: (Injector i) => new NgBindTypeForDateLike(i.getByKey(ELEMENT_KEY)));
606+
toFactory: (dom.Element e) => new NgBindTypeForDateLike(e), inject: [dom.Element]);
607607
final dom.InputElement inputElement;
608608
final NgModel ngModel;
609609
final NgModelOptions ngModelOptions;

lib/mock/module.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ class AngularMockModule extends Module {
6262
bind(MockHttpBackend);
6363
bind(Element, toValue: document.body);
6464
bind(Node, toValue: document.body);
65-
bind(HttpBackend, toFactory: (Injector i) => i.getByKey(MOCK_HTTP_BACKEND_KEY));
66-
bind(VmTurnZone, toFactory: (_) {
65+
bind(HttpBackend, inject: [MockHttpBackend]);
66+
bind(VmTurnZone, toFactory: () {
6767
return new VmTurnZone()
6868
..onError = (e, s, LongStackTrace ls) => dump('EXCEPTION: $e\n$s\n$ls');
69-
});
69+
}, inject: []);
7070
bind(Window, toImplementation: MockWindow);
7171
var mockPlatform = new MockWebPlatform();
7272
bind(MockWebPlatform, toValue: mockPlatform);

lib/mock/test_injection.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ class _SpecInjector {
1616

1717
_SpecInjector() {
1818
var moduleModule = new Module()
19-
..bind(Module, toFactory: (Injector injector) => addModule(new Module()));
19+
..bind(Module, toFactory: () => addModule(new Module()), inject: []);
2020
moduleInjector = new DynamicInjector(modules: [moduleModule]);
2121
}
2222

2323
addModule(module) {
2424
if (injector != null) {
25-
throw ["Injector already crated, can not add more modules."];
25+
throw ["Injector already created, can not add more modules."];
2626
}
2727
modules.add(module);
2828
return module;

lib/routing/module.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ part 'ng_bind_route.dart';
142142
class RoutingModule extends Module {
143143
RoutingModule({bool usePushState: true}) {
144144
bind(NgRoutingUsePushState);
145-
bind(Router, toFactory: (injector) {
146-
var useFragment = !injector.getByKey(NG_ROUTING_USE_PUSH_STATE_KEY).usePushState;
147-
return new Router(useFragment: useFragment, windowImpl: injector.getByKey(WINDOW_KEY));
148-
});
145+
bind(Router, toFactory: (NgRoutingUsePushState state, Window window) {
146+
var useFragment = !state.usePushState;
147+
return new Router(useFragment: useFragment, windowImpl: window);
148+
}, inject: [NG_ROUTING_USE_PUSH_STATE_KEY, WINDOW_KEY]);
149149
bind(NgRoutingHelper);
150150
bind(RouteProvider, toValue: null);
151151
bind(RouteInitializer, toValue: null);

test/core/parser/generated_getter_setter_spec.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'generated_getter_setter.dart' as gen;
77
main() {
88
describe('hybrid getter-setter', () {
99
beforeEachModule((Module module) {
10-
module..bind(Parser, toFactory: (i) => i.get(DynamicParser))
10+
module..bind(Parser, inject: [DynamicParser])
1111
..bind(ClosureMap, toValue: gen.closureMap);
1212
});
1313
parser_spec.main();

test/core_dom/view_spec.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ main() {
199199
..bind(Log)
200200
..bind(AFormatter)
201201
..bind(ADirective)
202-
..bind(Node, toFactory: (injector) => document.body);
202+
..bind(Node, toFactory: () => document.body, inject: []);
203203

204204
Injector rootInjector = applicationFactory()
205205
.addModule(rootModule)

test/routing/routing_spec.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ main() {
1616
router = new Router(useFragment: false, windowImpl: new MockWindow());
1717
m
1818
..install(new AngularMockModule())
19-
..bind(RouteInitializerFn, toFactory: (_) => initRoutes)
19+
..bind(RouteInitializerFn, toFactory: () => initRoutes, inject: [])
2020
..bind(Router, toValue: router);
2121
});
2222

0 commit comments

Comments
 (0)