title: Adding Asp .NET Core Controller dynamically when analyzing route
body: <p>Summary:</p>
  <p>Imagine we are calling the url http://localhost:5600/Student/All/
  My goal is that my Asp .NET Core Web Api compiles a Student controller on the fly when that route is called and then uses that controller for answering that request.</p>
  <p>Detailed:</p>
  <p>I want to compile an Asp .NET Core Controller when analyzing the route. So I'm using a DynamicRouteValueTransfer to analyze the route and modify it when needed.</p>
  <pre><code>app.UseEndpoints(endpoints =&gt;
  {
      //...
      endpoints.MapDynamicControllerRoute&lt;SearchValueTransformer&gt;(&quot;{controller}/{action}/{**params}&quot;);
      //...
  </code></pre>
  <p>In the SearchValue Transfer (inherited from DynamicRouteValueTransfer) I can analyze and rewrite the route. There I'm compiling an Controller with a Get method which returns a list of Students (with an OData - [EnableQuery] - attribute because in the end I want to provide any data for OData access).</p>
  <p>Then I try to add this newly compiled StudentController to the Controllers to be used in that request. But that is <strong>not</strong> working.</p>
  <p>I tried saving the IMvcBuilder which I get at startup at the ConfigureServices:</p>
  <pre><code>//inside ConfigureServices - MvcManager is my static class
  MvcManager.Builder = services.AddMvc();
  
  //in my static class
  public static IMvcBuilder Builder { get; set; }
  </code></pre>
  <p>After compiling the Controller I tried to add that Assembly by calling</p>
  <pre><code>MvcManager.Builder.AddApplicationPart(assembly).AddControllersAsServices();
  </code></pre>
  <p>The problem is that I can't go into that controller. I found some articles about dynamically adding but none is doing it while the request is already started.</p>