# Newbie question about injecting service in controller without authentication

**URL:** <https://discourse.cakephp.org/t/newbie-question-about-injecting-service-in-controller-without-authentication/10239>\
**Category:** Need Help\
**Created:** [March 21, 2022, 9:43pm UTC](https://discourse.cakephp.org/t/newbie-question-about-injecting-service-in-controller-without-authentication/10239 "2022-03-21T21:43:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![caclulon](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@caclulon](https://discourse.cakephp.org/u/caclulon)\
**Post date:** [March 21, 2022, 9:43pm UTC](https://discourse.cakephp.org/t/newbie-question-about-injecting-service-in-controller-without-authentication/10239/1 "2022-03-21T21:43:11Z")

</div>

Hi,  
I play around with the examples from the documentation.  
But when i want to inject a service into the constructor of a controller

```auto
   public function __construct(UserAvatarService $userAvatarService)
    {
        parent::__construct();
        $this->userAvatarService = $userAvatarService;
    }

```

i get following error:

> The request object does not contain the required `authentication` attribute

When i put

> $this-\>loadComponent(‘Authentication.Authentication’);

into the beforeFilter Section of the AppController, i get an error with too many redirects.

Has anyone a good solution to inject a service into an controller without these authentification issues?

Thanks  
David

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [March 21, 2022, 10:05pm UTC](https://discourse.cakephp.org/t/newbie-question-about-injecting-service-in-controller-without-authentication/10239/2 "2022-03-21T22:05:35Z")

</div>

Dont use the constructor of the controller. Just append your service to the parameters of your function where you need it.
