# Lost application instance when ember build

**URL:** <https://discuss.emberjs.com/t/lost-application-instance-when-ember-build/9230>\
**Category:** Uncategorized\
**Created:** [December 2, 2015, 9:03am UTC](https://discuss.emberjs.com/t/lost-application-instance-when-ember-build/9230 "2015-12-02T09:03:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tangmonk](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tangmonk/32/11716_2.png) [@tangmonk](https://discuss.emberjs.com/u/tangmonk)\
**Post date:** [December 2, 2015, 9:03am UTC](https://discuss.emberjs.com/t/lost-application-instance-when-ember-build/9230/1 "2015-12-02T09:03:44Z")

</div>

I have a ember-cli project named `Car`,

I can access `Car` object from window.Car, It seems ember-cli create a global object for me on development env.

But if I run `serve build` , I am lost the `Car`.

I will create a initializer and create the `Car` manually if there is no better way.

---

<div class="post-metadata">

**Author:** ![workmanw](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/workmanw/32/14929_2.png) [@workmanw](https://discuss.emberjs.com/u/workmanw)\
**Post date:** [December 2, 2015, 2:44pm UTC](https://discuss.emberjs.com/t/lost-application-instance-when-ember-build/9230/2 "2015-12-02T14:44:20Z")

</div>

I think this might be usful: [GitHub - ember-cli/ember-export-application-global](https://github.com/ember-cli/ember-export-application-global) . But I’ve never used it so I don’t know.

In our app, we have an initializer (like you suggested) that does this work for us. It looks like this:

```
// app/initializers/app-setup.js
export default {
  name: 'app-setup',
  initialize: function(container, application) {
    window.BC = application;
  }
};

```

We use the initializer because we have more setup to do as well. We have data embedded by server into the HTML that needs to be configured on the application (CSRF for example).

---

<div class="post-metadata">

**Author:** ![tangmonk](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tangmonk/32/11716_2.png) [@tangmonk](https://discuss.emberjs.com/u/tangmonk)\
**Post date:** [December 3, 2015, 1:59am UTC](https://discuss.emberjs.com/t/lost-application-instance-when-ember-build/9230/3 "2015-12-03T01:59:51Z")

</div>

Thanks for you reply, I wanna why ember developers remove the global application instance when build.

I store some static data in the global instance, like api host url.

Am I lost the best practice?

---

<div class="post-metadata">

**Author:** ![workmanw](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/workmanw/32/14929_2.png) [@workmanw](https://discuss.emberjs.com/u/workmanw)\
**Post date:** [December 3, 2015, 2:06am UTC](https://discuss.emberjs.com/t/lost-application-instance-when-ember-build/9230/4 "2015-12-03T02:06:20Z")

</div>

Yea, generally speaking, you should not use the global instance within your app. So doing `window.App.hostUrl` from inside the app (controller, component, adapter, etc) is a bad practice because it makes testing and other things more complicated. If you need to access `hostUrl` put it in a “config” service and use `config: Ember.inject.service()` where ever you need to access it.

You should only use `window.App` for debugging or some setup that happens outside the scope of the app.

---

<div class="post-metadata">

**Author:** ![tangmonk](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tangmonk/32/11716_2.png) [@tangmonk](https://discuss.emberjs.com/u/tangmonk)\
**Post date:** [December 3, 2015, 2:09am UTC](https://discuss.emberjs.com/t/lost-application-instance-when-ember-build/9230/5 "2015-12-03T02:09:30Z")

</div>

I see, thanks!😄

---

<div class="post-metadata">

**Author:** ![workmanw](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/workmanw/32/14929_2.png) [@workmanw](https://discuss.emberjs.com/u/workmanw)\
**Post date:** [December 3, 2015, 2:10am UTC](https://discuss.emberjs.com/t/lost-application-instance-when-ember-build/9230/6 "2015-12-03T02:10:00Z")

</div>

You’re welcome! Happy Embering.
