Allow setting of configuration at runtime in ASP.NET MVC/WebAPI #108
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.
In relation to #93
Here's a simple solution to allow converting the
Bugsnag.ConfigurationSection.Configuration
object constructed from web/app.config when callingBugsnag.ConfigurationSection.Configuration.Settings
in to an instance ofBugsnag.Configuration
that allow properties to be changed at runtime.This would allow you to leverage the configuration section for the majority of static date, while allowing you to dynamically set one or more properties at runtime.
Here's an example:
Goal
Allow quick cloning of ConfigurationSection.Configuration in to a writable Configuration object.
Allow setting configuration values at runtime (during app start-up), and reusing these instead of always using the values from app/web.config
Design
Beside constructing a Bugsnag.Configuration object by copying the values from Bugsnag.ConfigurationSection.Configuration.Settings which is simple enough to give you a configuration object that can be changed at runtime, this doesn't address the fact that Bugsnag.AspNet.Client.Current always goes back to the config file when a new instance is created.
To allow a custom configuration throughout ASP.NET, we need to store a copy of this configuration centrally. For this I have created a static instance under Bugsnag.AspNet.Client that will hold the configuration for the lifetime of the application.
Bugsnag.AspNet.Client.Current has then been updated to use this instance when the per-request client is constructed, or when the fallback 'global' client is constructed.
While this design does not allow the configuration of the global client to be changed after initial construction, I think this may be a suitable tradeoff to allow a more dynamic configuration at the per-request level.
Changeset
Added
An extension method in Bugsnag.ConfigurationSection.ConfigurationExtensions
A static property to hold the runtime configuration in Bugsnag.AspNet.Client
Changed
Changed Bugsnag.AspNet.Client.Current to use the new runtime configuration (which falls back to using the configuration file values if not explicitly set)
Linked issues
Related to #93
Review
Please note this is not extensively tested, and not something I expect to be merged without more thought and discussion from the Bugsnag team. :)
For the submitter, initial self-review:
For the pull request reviewer(s), this changeset has been reviewed for: