Cannot call service: "'MyPlugin' not found" error I'm sure this is a trivial mistake but I can't figure it out (first-time plugin dev).

I have my plugin running with all code in the controller and want now follow best practice and move the workhorse code into a service class.

My main plugin code is

namespace ns\yutulic;
use ns\yutulic\models\SettingsModel;
use craft\models\Section;

public function init() {

    parent::init();

    self::$plugin = $this;

    $settings = $this-&gt;getSettings();
    $settings-&gt;sectionOptions = $this-&gt;setSectionOptions();

    // Register services
    $this-&gt;setComponents([
        'videoentries' =&gt; \ns\yutulic\services\VideoEntriesService::class,
    ]);

    $data = $this-&gt;videoentries-&gt;scanForVideos(null); // works

}


The relevant controller code is

Class ScanController extends Controller {
    public function actionScanEntries() {
        // Neiter works :-(
        //$data = Yutulic::$plugin-&gt;videoentries-&gt;scanForVideos($id);
        $data = Yutulic::getInstance()-&gt;videoentries-&gt;scanForVideos($id); // (*)
    }
}


And my service code:

&lt;?php
namespace ns\yutulic\services;
use ns\yutulic\Yutulic;
use Craft;
use craft\base\Component;

class VideoEntriesService extends Component
{
    public function scanForVideos($sectionId = null) {
        echo "Works!!!";
        return null;
    }
}


Even if I use the example of the docs it fails with the same error message on the line indicated (*) in the controller (but with the 'Foo' class name):

Class 'ns\yutulic\Yutulic' not found


This shouldn't be so hard?
I found the issue. The author of the tutorial I copied my first code from made the unfortunate choice to not use a proper plugin class:

class Plugin extends \craft\base\Plugin { ... }


To fix the problem, I replaced this line with

use Craft;
use craft\base\Plugin;
class Yutulic extends Plugin { ... }


and had to add a reference to the class to my controller and service modules:

use ns\yutulic\Yutulic;