Skip to content

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

Merged
merged 6 commits into from
Jan 4, 2019

Conversation

tsimbalar
Copy link
Member

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.

  • make only one constructor of ConfigurationReader public to make it clearer that we always expect a ConfigSection and optionally a full IConfiguration.
  • introduce the AssemblyFinder abstract class that takes care of locating assemblies from DependencyContext or from DLL-scanning, and make it clearer that we try to automatically guess which one to use when not explicitly specified.
  • move all the code related to locating assemblies under the *.Assemblies namespace
  • introduce ResolutionContext that keeps track of the values that can be useful when calling configuration methods (Level switches, the actual IConfiguration object) that is passed around when processing sub-sections of the config file.
  • reduce the number of parameters of the ConfigurationReader class
  • centralize the case-insensitive match strategy used when matching settings values to method parameters
  • align naming with the usual serilog projects conventions

I 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

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
@nblumhardt
Copy link
Member

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...

Copy link
Contributor

@skomis-mm skomis-mm left a 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.


public ResolutionContext(IConfiguration appConfiguration = null)
{
_declaredLevelSwitches = new Dictionary<string, LoggingLevelSwitch>();
Copy link
Contributor

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks !

Copy link
Member Author

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 Dictionarys ... 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 ?

@@ -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>();

Copy link
Contributor

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)

Copy link
Member Author

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 Dictionarys ... 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 ?

@skomis-mm
Copy link
Contributor

@tsimbalar Thanks! Let push this to the dev to try this in the wild 👍

@skomis-mm skomis-mm merged commit c8dcb96 into serilog:dev Jan 4, 2019
@tsimbalar tsimbalar deleted the fix/unskip-test branch January 4, 2019 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unskip the skipped test / no longer rely on static state
3 participants