We have a view helper class that shows online or offline status. This is based on a singleton object that lets the view know if a given user is online or offline. Instead of creating a global singleton, I was hoping to use the DI container in Ember.
An example of how DI works in ember can be found here - Some Improvement ideas for our DI subsystem
// assume app-wide scope App.inject(thingToInjectOn, property, thingToInject); App.register(thingToInject, factory); App.register('store:main', Store); // example form ED. Injection on all contorllers App.inject('controller', 'store', 'store:main'); // injection on a specific controller App.inject('controller:person', 'facebook', 'service:facebook');
This works. I would like to do the same with views
App.register('app:presence', Presence); App.inject('view', 'presence', 'app:presence');
While the container works great with injection of dependent objects for routes and controller, I was unable to inject a dependent object in the view. I would like some input on what is the right approach here and if it is ok to inject objects into views ?