title: Is is possible to inject to .net core DI container the IAgent interface
body: <p>I'm using NewRelic to gain insight on my system, In order to add custom attribute to the new-relic's transaction, I'm resolving the <code>IAgent</code> interface with <code>NewRelic.Api.Agent.NewRelic.GetAgent()</code> (<a href="https://docs.newrelic.com/docs/agents/net-agent/net-agent-api/getagent/" rel="nofollow noreferrer">docs</a>)</p>
  <p>Like:</p>
  <pre><code>public async Task&lt;IActionResult&gt; MyMethod([FromBody]MyRequest request)
  {
      //Do Some logic.
  
      IAgent agent = NewRelic.Api.Agent.NewRelic.GetAgent();
      ITransaction transaction = agent.CurrentTransaction;
      transaction.AddCustomAttribute(&quot;MyCustomAttribute&quot;, SomeValue)
  
      return Ok(...);
  }
  </code></pre>
  <p>Is it possible to use the dependency injection container in order to resolve the <code>IAgent</code> interface? like:</p>
  <pre><code>[ApiController]
  public class MyController
  {
      private readonly IAgent _agnet;
      public MyController(IAgent agent)
      {
          _agent = agent;
      }
  
      public async Task&lt;IActionResult&gt; MyMethod([FromBody]MyRequest request)
      {
           //Do Some logic.
  
           ITransaction transaction = this._agent.CurrentTransaction;
           transaction.AddCustomAttribute(&quot;MyCustomAttribute&quot;, SomeValue)
  
           return Ok(...);
      }
  }
  </code></pre>