应用程序初始化程序和ember中的服务有什么区别? [英] What is the difference between application initializer and a service in ember?

查看:43
本文介绍了应用程序初始化程序和ember中的服务有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我是ember的新手,所以在应用程序初始化程序和服务之间感到困惑。据我所知,他们两个都在做同样的工作,并且都拥有应用程序的生命周期。有人可以用一个清晰​​的例子来说明它们之间的区别吗?

As I am new to ember, I got confused between the application initializer and a service. To my knowledge, both of them was doing the same job and both have the lifetime of the application. Could anyone please explain the difference between them with a clear example?

推荐答案

Application Initializer是我们进行初始化或注册或注入的地方我们的新工厂类别或任何服务。
并且服务和Application Initializer初始化的类(工厂)都可以像使用单例一样将其状态共享到使用的每个路由。
使用applicationInstance.lookup()方法,我们甚至可以使用任何Application Initializer初始化的类,这些类在创建时不会在最初被注入,并且还可以共享其状态

Application Initializer is a place where we initialize or Register or inject our new factory classes or any Services. And Both services and Application Initializer initialized class(factory) can share their states like a singleton to every routes they were used . Using applicationInstance.lookup() method we can even use any Application Initializer initialized class in which they were'nt injected initially when they were created and can share their states as well

这篇关于应用程序初始化程序和ember中的服务有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆