Answers.Body: <p>You can call the main plugin class directly</p>
  
  <pre><code>MobileDetect::$plugin-&gt;mobileDetectService
  </code></pre>
  
  <p>I don't know this plugin, maybe the class is wrong but that's the syntax you can use </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T19:57:47.320Z
Answers.Text: Got it, and it will be the same instance I guess right? The "last" thing what I bother to call the service it self ->mobileDetectService... 
  There should be a better way I mean is there any service container what I can call instead?
Answers.UserDisplayName: Visky Máté
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T20:03:18.153Z
Answers.Text: You instance of the plugin is your service container. Services are components and they are registered in your (singleton) plugin instance. I'm not really sure what you mean by "better" way.
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-14T19:56:06.610Z
Answers.LastActivityDate: 2018-05-14T19:56:06.610Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I would like to use another plugin from my own plugin. What is the best way to do this. Right now I am doing something like this, but there should be a better way than to explicitly call the service:</p>
  
  <pre><code>Craft::$app-&gt;getModule('mobile-detect')-&gt;mobileDetectService
  </code></pre>
  
  <p>What I am really looking for is the service container where I do not have to know anything just the plugin what should have been loaded...?</p>
  
Tags: <plugin-development>
Title: Use a plugin from another plugin in Craft 3
ThreadText: # Use a plugin from another plugin in Craft 3
  
  (Asked by: username_0 on 2018-05-14)
  
  I would like to use another plugin from my own plugin. What is the best way to do this. Right now I am doing something like this, but there should be a better way than to explicitly call the service:
  
  ```
  Craft::$app->getModule('mobile-detect')->mobileDetectService
  
  ```
  
  What I am really looking for is the service container where I do not have to know anything just the plugin what should have been loaded...?
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-05-14. Score: 3 | Accepted answer
  
  You can call the main plugin class directly
  
  ```
  MobileDetect::$plugin->mobileDetectService
  
  ```
  
  I don't know this plugin, maybe the class is wrong but that's the syntax you can use
  
  > **Comments:**
  > **username_0**: Got it, and it will be the same instance I guess right? The "last" thing what I bother to call the service it self ->mobileDetectService...  There should be a better way I mean is there any service container what I can call instead?  
  > **username_1**: You instance of the plugin is your service container. Services are components and they are registered in your (singleton) plugin instance. I'm not really sure what you mean by "better" way.  
  
  ---
  
  