-
Notifications
You must be signed in to change notification settings - Fork 130
No longer rely on static state in ConfigurationReader #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
To pass around the `IConfiguration` object instead of a `static` member
and simplify some method signatures
to avoid checks for null dependencyContext in ConfigurationReader and split responsabilities
and reduce number of arguments to pass around
Looks awesome; not sure how the static state there slipped past me, I am not in this headspace enough right now to trust myself to review this PR, but LGTM on the surface! :-) .. Hoping someone with a little more time spare can go through it properly... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @tsimbalar . Looks great overall 👍 . Added some comments. One change is required (regarding DependencyContext.Default
check) other probably can be addressed in separate PR(s) if you think so.
...erilog.Settings.Configuration/Settings/Configuration/Assemblies/DllScanningAssemblyFinder.cs
Show resolved
Hide resolved
|
||
public ResolutionContext(IConfiguration appConfiguration = null) | ||
{ | ||
_declaredLevelSwitches = new Dictionary<string, LoggingLevelSwitch>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably better to initialize Dictionary with case insentitive comparer (to align with other places)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thanks !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reviewing the code, I see that we are not using any case insensitive comparer anywhere where we initialize Dictionary
s ... I'd rather not do the change (at least not in this PR), in order not to introduce any subtle bugs.
Shall we open a separate issue to keep track of it ?
src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/AssemblyFinder.cs
Show resolved
Hide resolved
@@ -265,11 +253,11 @@ string GetSectionName(IConfigurationSection s) | |||
} | |||
} | |||
|
|||
IReadOnlyCollection<Assembly> LoadConfigurationAssemblies() | |||
static IReadOnlyCollection<Assembly> LoadConfigurationAssemblies(IConfigurationSection section, AssemblyFinder assemblyFinder) | |||
{ | |||
var assemblies = new Dictionary<string, Assembly>(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably better to initialize Dictionary with case insentitive comparer (to align with other places)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as above :
After reviewing the code, I see that we are not using any case insensitive comparer anywhere where we initialize
Dictionary
s ... I'd rather not do the change (at least not in this PR), in order not to introduce any subtle bugs.Shall we open a separate issue to keep track of it ?
src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/AssemblyFinder.cs
Show resolved
Hide resolved
and protect against null
@tsimbalar Thanks! Let push this to the dev to try this in the wild 👍 |
We had a commented out test that failed in a non deterministic way, because of
static
state.This PR removes that static state altogether, and un-skips that test.
As part of this PR I also did quite a bit of refactoring as I was trying to wrap my head about its behavior :). I also tried to move some code out of
ConfigurationReader
which is starting to grow big.ConfigurationReader
public to make it clearer that we always expect aConfigSection
and optionally a fullIConfiguration
.AssemblyFinder
abstract class that takes care of locating assemblies fromDependencyContext
or from DLL-scanning, and make it clearer that we try to automatically guess which one to use when not explicitly specified.*.Assemblies
namespaceResolutionContext
that keeps track of the values that can be useful when calling configuration methods (Level switches, the actualIConfiguration
object) that is passed around when processing sub-sections of the config file.ConfigurationReader
classI did get a bit carried away, and the diffs ends up being quite big and possibly hard to review. If you think it is necessary, I can try and split this PR into multiple commits.
fixes #147