Add IServiceCollection
extension methods to register ApmAgent
#2326
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2262
Newer releases of .NET have moved away from the older
IHostBuilder
andIApplicationBuilder
mechanisms in Microsoft.Extensions.Hosting. To support registering theApmAgent
consistently in all templates which use the generic host from Microsoft.Extensions.Hosting, this PR adds support for registering the agent via theIServiceCollection
. This mechanism is now favoured as it is consistent and expected to be a viable long-term choice.This PR also refactors the original tests for the Extensions.Hosting and Extensions.Logging libraries. Because the ApmAgent is a singleton, test cases cannot make assertions in isolation. To work around this, the test cases now spin up a test app in a separate process. The test app accepts various args to configure its behaviour so that the key test conditions can be applied and validated.
Docs are updated to reflect the new extension methods.