Dependency injection and constructors - what really happens

use Drupal\Core\Controller\ControllerBase;
use Drupal\my_module\SomeClass;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;

class SomeController extends ControllerBase
{
    private $someProperty;

    public function __construct(SomeClass $someProperty)
    {
        $this->someProperty = $someProperty;
    }
    public static function create(ContainerInterface $container)
    {
        return new static(
         $container->get('some_service.some_name')
        );
    }
    public function some_method($variable)
    {
        $something = $this->someProperty->getSomething($variable);
        return new Response($something);
    }
}

I was confused for a lot of time with this code and what really happens here. And the proper way to read this would be to know that when "create" method is called it passes us a "container" which we use with get method and we assign some service with that method to our property $someProperty.

But that is mostly understood, what confused me was the __constructor and this "return new static" part. With new static we are basically creating a new object of the class we are in, which is SomeController, with that happening __constructor magic is also firing up as If you create a __construct() function, PHP will automatically call the __construct() method/function when you create an object from your class, so what happens is __construct is called here and we are assigning a property to a service, or you can look at "return new static" as we are calling a __construct with a "$container->get('some_service.some_name')" parametar. With that you can use methods from injected service in you other methods, like in some_method you are calling "getSomething" which is method from some_service.some_name that we didn't define here as it would be in that service file (which is just a class) but we can use as we injected this service through constructor. Hope it helps :)