Custom libraries and dependency injection I have been using D7 for a while, new to D8; also have a fair amount of experience with Laravel/Lumen and dependancy injection (DI).  One of the big sell's of D8 is the new OO structure, and specifically the Symphony DI system.

So to test this out, I want to develop (port some of my old D7 code) to a D8 custom library, that will 'inject' when needed, and I do not want to do this as a module (I got that right; the objective is to have a PHP library class).

Given some of the documentation I read, I created a folder called /libraries/my_library, and for the hell of it I added a PSR4 mapping to /composer.json like so:

"Drupal\\CustomLib\\": "libraries"

For the record, I tried it without Drupal\\ as well - makes no difference.

In /libraries/my_library/scr/myClass.php I have a single class myClass.  I also added a my_library.services.yml 

services:

  myClass:
    class:   CustomLib\mylibrary\myClass


And in my custom theme file I simply tried

use CustomLib\mylibrary;

function quirk_preprocess_html(&amp;$vars) {
  $tools = Drupal::service('myClass');
}


which results in 


Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service


Can someone point me in the right direction please.  What am I missing.  I am assuming Drupal is not scanning the /libraries/my_library folder for the services definition - but how do I get it to do so?
OK people, I played around with a couple of options, but the bottom line is, if you want to create your own 'services' class, specifically for dependancy injection, it has to be tied to a module.

So - I created a custom module.  The actual module file is empty

&lt;?php


Also created the services definition / config file my_module.services.yml and then critically, your services class files should go in a sub-folder /src.  Since it is a service, you will need an interface and implementation class.