title: C# how to "register" class "plug-ins" into a service class?
body: <p><strong>Update#2 as of year 2022</strong></p>
  <p>All these years have passed and still no good answer.
  Decided to <a href="https://stackoverflow.com/questions/73537998/c-sharp-how-to-register-class-plug-ins-into-a-service-class-as-of-today">revive</a> this question.</p>
  <hr />
  <p>I'm trying to implement something like the idea I'm trying to show with the following diagram (end of the question).</p>
  <p>Everything is coded from the <code>abstract class Base</code> till the <code>DoSomething</code> classes.</p>
  <p>My &quot;Service&quot; needs to provide to the consumer &quot;actions&quot; of the type &quot;DoSomethings&quot; that the service has &quot;registered&quot;, at this point I am seeing my self as repeating (copy/paste) the following logic on the service class:</p>
  <pre><code>public async Task&lt;Obj1&lt;XXXX&gt;&gt; DoSomething1(....params....)
          {
              var action = new DoSomething1(contructParams);
              return await action.Go(....params....);
          }
  </code></pre>
  <p>I would like to know <strong>if there is anyway in C# to &quot;register&quot; all the &quot;DoSomething&quot; I want in a different way?</strong> Something more dynamic and less &quot;copy/paste&quot; and at the same time provide me the &quot;intellisense&quot; in my consumer class? Somekind of &quot;injecting&quot; a list of accepted &quot;DoSomething&quot; for that service.</p>
  <p><strong>Update#1</strong>
  After reading the sugestion that PanagiotisKanavos said about MEF and checking other options of IoC, I was not able to find exactly what I am looking for.</p>
  <p>My objective is to have my <code>Service1</code> class (and all similar ones) to behave like a <code>DynamicObject</code> but where the accepted methods are defined on its own constructor (where I specify exactly which <code>DoSomethingX</code> I am offering as a method call.</p>
  <p><strong>Example</strong>:
  I have several actions (DoSomethingX) as &quot;BuyCar&quot;, &quot;SellCar&quot;, &quot;ChangeOil&quot;, &quot;StartEngine&quot;, etc....
  Now, I want to create a service &quot;CarService&quot; that only should offer the actions &quot;StartEngine&quot; and &quot;SellCar&quot;, while I might have other &quot;Services&quot; with other combination of &quot;actions&quot;. I want to define this logic inside the constructor of each service. Then, in the consumer class, I just want to do something like:</p>
  <pre><code>var myCarService = new CarService(...paramsX...);
  var res1 = myCarService.StartEngine(...paramsY...);
  var res2 = myCarService.SellCar(...paramsZ...);
  </code></pre>
  <p>And I want to offer intellisense when I use the &quot;CarService&quot;....</p>
  <p><strong>In conclusion:</strong> The objective is how to &quot;register&quot; in each Service which methods are provided by him, by giving a list of &quot;DoSomethingX&quot;, and automatically offer them as a &quot;method&quot;... I hope I was able to explain my objective/<strong>wish</strong>.</p>
  <p><strong>In other words:</strong> I just want to be able to say that my class <code>Service1</code> is &quot;offering&quot; the actions <code>DoSomething1, DoSomething2</code> and <code>DoSomething3</code>, but with the minimum lines as possible. Somehow the concept of the use of class attributes, where I could do something similar to this:</p>
  <pre><code>// THEORETICAL CODE
  [RegisterAction(typeOf(DoSomething1))]
  [RegisterAction(typeOf(DoSomething2))]
  [RegisterAction(typeOf(DoSomething3))]
  public class Service1{
      // NO NEED OF EXTRA LINES....
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/HCjrM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HCjrM.png" alt="enter image description here" /></a></p>