# Component injection fails

**URL:** https://discuss.emberjs.com/t/component-injection-fails/6566
**Category:** Uncategorized
**Created:** [October 24, 2014, 8:18pm UTC](https://discuss.emberjs.com/t/component-injection-fails/6566 "2014-10-24T20:18:52Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![typeoneerror](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/typeoneerror/32/9459_2.png) [@typeoneerror](https://discuss.emberjs.com/u/typeoneerror)
#### Post date: [October 24, 2014, 8:18pm UTC](https://discuss.emberjs.com/t/component-injection-fails/6566/1 "2014-10-24T20:18:52Z")

</div>

I’ve got a simple initializer that injects a singleton class into views and components. When I use the component in a template like

```
{{component-name}}

```

I am then able to access the injected object from the component.

If I create an instance of the component from code:

```
comp = App.ComponentNameComponent.create()

```

the injected object is null.

Does injection only work on components added via a template? Is there something special I need to do to inject into components that I want to manage programmatically?

---

<div class="post-metadata">

### Author: ![mixonic](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mixonic/32/14829_2.png) [@mixonic](https://discuss.emberjs.com/u/mixonic)
#### Post date: [October 25, 2014, 2:27am UTC](https://discuss.emberjs.com/t/component-injection-fails/6566/2 "2014-10-25T02:27:26Z")

</div>

Ember’s DI system works through an application container. Creating a raw instance of a class will not result in an injection being made.

There is a guide on DI at the Ember website. Creating instances by hand should really not be needed- maybe you can provide more context about your use case.

---

<div class="post-metadata">

### Author: ![typeoneerror](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/typeoneerror/32/9459_2.png) [@typeoneerror](https://discuss.emberjs.com/u/typeoneerror)
#### Post date: [October 25, 2014, 5:00am UTC](https://discuss.emberjs.com/t/component-injection-fails/6566/3 "2014-10-25T05:00:50Z")

</div>

Thanks, @mixonic, I think I got it figured out.

---

<div class="post-metadata">

### Author: ![ianstarz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ianstarz/32/4520_2.png) [@ianstarz](https://discuss.emberjs.com/u/ianstarz)
#### Post date: [October 28, 2014, 4:20pm UTC](https://discuss.emberjs.com/t/component-injection-fails/6566/4 "2014-10-28T16:20:54Z")

</div>

How about for objects loaded by es6 modules (ember cli)? Does creating a new instance like the following result in the injection being made?

```
import ComponentNameComponent from 'app/components/component-name';
comp = ComponentNameComponent.create();

```
