The goal of the container is to provide a more general-purpose mechanism for describing module dependencies than the ad-hoc approach we had been using.
For example, imagine you want to find the controller for the post
route. The default Ember rules are that we would look it up as App.PostController
. Before the container, we would just hardcode those rules wherever we needed to do the lookup (using classify
and friends).
The container provides a way for us to define those rules in a single place. As a bonus, the rules can be overridden for applications that want a different convention.
So instead of Ember.get(namespace, Ember.String.classify(name) + 'Controller')
internally, we now do container.lookup('controller:' + name)
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…