title: Add property to all responses in asp.net core
body: <p>I have an API with multiple endpoints. I'd like to add a property to all endpoint responses, without adding it to each endpoint response model individually.</p>
  <p>Ex:</p>
  <pre><code>public class MyClass
  {
      public string MyProperty { get; set; } = &quot;Hello&quot;;
  }
  
  public class MyOtherClass
  {
      public string MyOtherProperty { get; set; } = &quot;World&quot;;
  }
  
  public class MyController : ControllerBase
  {
      [HttpPost]
      public async Task&lt;ActionResult&lt;MyClass&gt;&gt; EndpointOne(POSTData data)
      {
          // implementation omitted
      }
  
      [HttpPost]
      public async Task&lt;ActionResult&lt;MyOtherClass&gt;&gt; EndpointTwo(POSTOtherData otherData)
      {
          // implementation omitted
      }
  }
  </code></pre>
  <p>Calling either endpoint returns a JSON representation of <code>MyClass</code> or <code>MyOtherClass</code> as appropriate - i.e.</p>
  <pre><code>{ &quot;MyProperty&quot;:&quot;Hello&quot; } or { &quot;MyOtherProperty&quot;:&quot;World&quot; }
  </code></pre>
  <p>I want to add a property, say a string <code>ApiName</code>, to all endpoints in the API, so that the result of the above code would be either (as appropriate)</p>
  <pre><code>{ &quot;MyProperty&quot;:&quot;Hello&quot;, &quot;ApiName&quot;:&quot;My awesome API&quot; } 
  </code></pre>
  <p>or</p>
  <pre><code>{ &quot;MyOtherProperty&quot;:&quot;World&quot;, &quot;ApiName&quot;:&quot;My awesome API&quot; }
  </code></pre>
  <p>Is there a way to hook into the JSON-stringified result just before returning and add a top-level property like that? If so, I presume I'd have to wire it up in <code>startup.cs</code>, so I've been looking at <code>app.UseEndpoints(...)</code> methods, but haven't found anything that's worked so far. Either it's not added the property, or it's replaced the original result with the new property.</p>
  <p>Thanks in advance!</p>