# Inject custom attribute

**URL:** <https://discourse.aurelia.io/t/inject-custom-attribute/5191>\
**Category:** vNext\
**Created:** [July 3, 2023, 8:36am UTC](https://discourse.aurelia.io/t/inject-custom-attribute/5191 "2023-07-03T08:36:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elitastic](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/elitastic/32/1787_2.png) [@elitastic](https://discourse.aurelia.io/u/elitastic)\
**Post date:** [July 3, 2023, 8:36am UTC](https://discourse.aurelia.io/t/inject-custom-attribute/5191/1 "2023-07-03T08:36:26Z")

</div>

In Au1, it was possible to inject a custom attribute (of a parent scope) in a custom element, in Au2 this is not possible anymore:

> **[custom attribute injection - StackBlitz](https://stackblitz.com/edit/au2-conventions-rjjfwj)**
>
> Run Aurelia application with conventions

Is this by design? Thanks for any help.

---

<div class="post-metadata">

**Author:** ![bigopon](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/bigopon/32/18_2.png) [@bigopon](https://discourse.aurelia.io/u/bigopon)\
**Post date:** [July 4, 2023, 3:50am UTC](https://discourse.aurelia.io/t/inject-custom-attribute/5191/2 "2023-07-04T03:50:21Z")

</div>

In v1, all including custom attributes participate in “component container hierarchy”, which is considered improper design and this has been removed in v2. In v2, only custom elements/specific template controllers participate in “component container hierarchy”. Maybe imagine custom attribute as leaf nodes of a tree. So to your question, it’s not possible to just inject. But you can always inject a hydration context and do the provide inject pair with the container there.

Example [custom attribute injection (forked) - StackBlitz](https://stackblitz.com/edit/au2-conventions-poxxaa?file=src%2Fmain.ts,src%2Ftest-custom-attribute.ts,src%2Fmy-app.html)

I’ve also tweak the `.register` calls in `main.ts` so you don’t have to repeat `.register` many times.

---

<div class="post-metadata">

**Author:** ![elitastic](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/elitastic/32/1787_2.png) [@elitastic](https://discourse.aurelia.io/u/elitastic)\
**Post date:** [July 4, 2023, 4:40am UTC](https://discourse.aurelia.io/t/inject-custom-attribute/5191/3 "2023-07-04T04:40:23Z")

</div>

This is great, thanks for your help!
