# Why static API for .net core agent?

**URL:** <https://discuss.elastic.co/t/why-static-api-for-net-core-agent/236465>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [June 10, 2020, 8:56am UTC](https://discuss.elastic.co/t/why-static-api-for-net-core-agent/236465 "2020-06-10T08:56:32Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [June 10, 2020, 9:25am UTC](https://discuss.elastic.co/t/why-static-api-for-net-core-agent/236465/2 "2020-06-10T09:25:20Z")

</div>

Hi @Marcin_Druzgala,

I wrote about why we need a singleton [here](https://github.com/elastic/apm-agent-dotnet/issues/824#issuecomment-617867168). If we let users new up tons of agent instances then it'd open up lots of other issues.

> It also makes it super hard to unit test code that uses `Agent.Tracer.CaptureTransaction` or `Agent.Tracer.CaptureSpan` (it is almost impossible to be honest - we have to refactor code to use the hack [Mock an APM instance](https://discuss.elastic.co/t/mock-an-apm-instance/224686/2)).

One suggestion I can give you is that you could just inject the `ITracer` instance (that's the `Agent.Tracer`) into the classes you test and in a test environment just set it to `null` and use it with `?.` in your code. That way if it's not prod and the agent is not configured there won't be traces and the API won't do anything.

> How will that singleton behave if we are using the APM tracing not only for http requests but also for rabbitmq events - since everything is a singleton is there a chance that by accessing agent singleton instance while we have both rabbitmq and http in progress might be problematic?

I don't think it'd be problematic, in fact in order to correlate all the spans we can't have independent agent instances. If you'd have 2 independent agent instances for the 2 libraries it'd be even harder to correlate them.

Now, having said that - there are already some issues in the agent repo around this topic to make some improvements. [This one](https://github.com/elastic/apm-agent-dotnet/issues/458) is an example.

---

_[View the full topic](https://discuss.elastic.co/t/why-static-api-for-net-core-agent/236465)._
