Answers.Body: <p>Assuming <code>Plugin1</code> is their main plugin class file name, you could do:</p>
  <pre><code>\fully\qualified\namespace\Plugin1::getInstance()-&gt;myService-&gt;myMethod();
  </code></pre>
  <p>In order for this to work:</p>
  <ol>
  <li>Craft must be installed.</li>
  <li><code>Plugin1</code> must be installed and enabled in Craft.</li>
  <li>Composer autoloading has to be working so that it knows where to find <code>Plugin1</code></li>
  </ol>
  <p>If you're doing this from a custom module, then you'll need to listen for the <code>EVENT_INIT</code> event, because plugins get instantiated after modules.</p>
  <p>i.e.</p>
  <pre><code>Craft::$app-&gt;on(Application::EVENT_INIT, function() {
      \fully\qualified\namespace\Plugin1::getInstance()-&gt;myService-&gt;myMethod();
  });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-18T00:52:10.183Z
Answers.Text: Thanks Brad, exactly what I was looking for.
Answers.UserDisplayName: Wei
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-13T03:19:03.883Z
Answers.Text: Doing this returns null on getInstance() on my end.  Could it be because my plugin class name is called Plugin and I need to name it something else?
Answers.UserDisplayName: biko
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-07T21:06:43.513Z
Answers.Text: Did you figure this out biko? I have the same issue.
Answers.UserDisplayName: Darryl Hardin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-23T17:12:31.197Z
Answers.Text: I have the same issue as Biko, i'm losing my mind over this
Answers.UserDisplayName: Kevon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-16T00:09:20.440Z
Answers.LastActivityDate: 2020-12-02T22:00:24.660Z
Answers.LastEditDate: 2020-12-02T22:00:24.660Z
Answers.UserDisplayName: Brad Bell
Body: <p>In Craft 2, we used to be able to do so by doing:</p>
  
  <pre><code>craft()-&gt;plugin1-&gt;myMethod();
  </code></pre>
  
  <p>from Plugin 2's service for example.</p>
  
  <p>Now in Craft 3, I couldn't figure out a way to do it.</p>
  
  <pre><code>Plugin1::$plugin-&gt;myService-&gt;myMethod();
  </code></pre>
  
  <p>seems to only work within the Plugin 1's code base.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-15T06:17:21.077Z
Comments.Text: It works as well in other plugins if they have a variable called `$plugin` maybe you could tell us the name of the other plugin? Also it's important where you call this method. If it's in your plugins init function chances are high the other plugin is not created at this time
Comments.UserDisplayName: Robin Schambach
Tags: <plugin-development><craft3><services>
Title: Craft 3: how to call methods in another plugin's service?
ThreadText: # Craft 3: how to call methods in another plugin's service?
  
  (Asked by: username_0 on 2019-02-14)
  
  In Craft 2, we used to be able to do so by doing:
  
  ```
  craft()->plugin1->myMethod();
  
  ```
  
  from Plugin 2's service for example.
  
  Now in Craft 3, I couldn't figure out a way to do it.
  
  ```
  Plugin1::$plugin->myService->myMethod();
  
  ```
  
  seems to only work within the Plugin 1's code base.
  
  **Tags:** plugin-development, craft3, services
  
  > **Comments:**
  > **username_1**: It works as well in other plugins if they have a variable called `$plugin` maybe you could tell us the name of the other plugin? Also it's important where you call this method. If it's in your plugins init function chances are high the other plugin is not created at this time  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-02-16. Score: 4 | Accepted answer
  
  Assuming `Plugin1` is their main plugin class file name, you could do:
  
  ```
  \fully\qualified\namespace\Plugin1::getInstance()->myService->myMethod();
  
  ```
  
  In order for this to work:
  
  1. Craft must be installed.
  2. `Plugin1` must be installed and enabled in Craft.
  3. Composer autoloading has to be working so that it knows where to find `Plugin1`
  
  If you're doing this from a custom module, then you'll need to listen for the `EVENT_INIT` event, because plugins get instantiated after modules.
  
  i.e.
  
  ```
  Craft::$app->on(Application::EVENT_INIT, function() {
      \fully\qualified\namespace\Plugin1::getInstance()->myService->myMethod();
  });
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks username_2, exactly what I was looking for.  
  > **username_3**: Doing this returns null on getInstance() on my end.  Could it be because my plugin class name is called Plugin and I need to name it something else?  
  > **username_4**: Did you figure this out username_3? I have the same issue.  
  > **username_5**: I have the same issue as username_3, i'm losing my mind over this  
  
  ---
  
  