Use services in controller
In this example you should inject dependencies via the controller create method, pass the container there, and return an array. The first item in the array is the service you’re passing to the constructor. 

Then, add a constructor that expects this object as an argument, and then set $this-&gt;membership to the container object you passed as an argument. This should also be a protected member of the class. 

But to see your example actually work first, remove the container from the test method and remove the line about $memebrship. Clear cache and hit that route to see Hello world!

Here is a similar question demonstrating this: How do I use dependency injection on \Drupal::moduleHandler() to a Controller?