What is the purpose of the Ember.Container

前端 未结 2 722
天涯浪人
天涯浪人 2020-12-02 23:47

Can anyone explain what the purpose of the Container module is in the latest Ember?

An example of its usage, in the setup and in the start of this test:



        
相关标签:
2条回答
  • 2020-12-03 00:17

    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).

    0 讨论(0)
  • 2020-12-03 00:40

    Intended for internal use.

    Not meant to be public API

    https://github.com/emberjs/ember.js/commit/5becdc4467573f80a5c5dbb51d97c6b9239714a8

    0 讨论(0)
提交回复
热议问题