Skip to content
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

Adding a simple switch to exclude unnecessary activations #35

Merged

Conversation

srogovtsev
Copy link

@srogovtsev srogovtsev commented Jun 24, 2020

An option 3 from #34:

create a switch, something like RegisterLogger(..., bool onlyForKnownConsumers: false), which will enable the behavior above [activation limiting] for implementation cases like ours

@srogovtsev srogovtsev changed the title Fixes nblumhardt/autofac-serilog-integration#34 by adding a simple switch to exclude unnecessary activations Fixes #34 by adding a simple switch to exclude unnecessary activations Jun 24, 2020
@srogovtsev srogovtsev changed the title Fixes #34 by adding a simple switch to exclude unnecessary activations Adding a simple switch to exclude unnecessary activations Jun 24, 2020
@srogovtsev srogovtsev changed the base branch from master to dev June 24, 2020 16:49
@srogovtsev srogovtsev force-pushed the feature/limiting-preparing-handlers branch from 0aafd1b to db03a39 Compare June 24, 2020 16:52
@@ -19,11 +19,15 @@ public static class SerilogContainerBuilderExtensions
/// <param name="autowireProperties">If true, properties on reflection-based components of type <see cref="ILogger"/> will
/// be injected.</param>
/// <param name="dispose"></param>
/// <param name="onlyKnownConsumers">
/// If true, only the registrations that can be verified to use <see cref="ILogger"/> will be modified to access the logger,
/// thus avoiding unnecessary logger calls.
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe "unnecessary reflection"?

Copy link
Author

Choose a reason for hiding this comment

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

It's actually not about reflection.

var log = args.Context.Resolve<ILogger>().ForContext(registration.Activator.LimitType);

Probably "resolution" would be most appropriate.

(BTW, this line has quite a potential for improving, because you don't have to resolve ILogger from container, you have all the information you need right here - and you'll skip redundant NamedParameter check as well)

@@ -26,11 +27,12 @@ public ContextualLoggingModule()
_skipRegistration = true;
}

internal ContextualLoggingModule(ILogger logger = null, bool autowireProperties = false, bool dispose = false)
internal ContextualLoggingModule(ILogger logger = null, bool autowireProperties = false, bool dispose = false, bool onlyKnownConsumers = false)
Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps the name should be reflectionActivatorsOnly?

Copy link
Author

Choose a reason for hiding this comment

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

I feel this would be a little too specific and breaking encapsulation. But you want to invert it anyway, so this is probably a moot point.

@nblumhardt
Copy link
Owner

Seems like a nice "contained" fix; I'd be inclined to consider a breaking change, and reverse this so it's an opt-out, e.g. the param would be includeDynamicRegistrations = false (or something like that). Very short on time, sorry about the laggy replies!

@srogovtsev
Copy link
Author

the param would be includeDynamicRegistrations = false (or something like that).

I'd go for injectWhenUnsure. Do you want me to update the PR with the breaking change?

@nblumhardt
Copy link
Owner

Thanks for the reply! Been trying to come up with another suggestion all week :-) - I think "unsure" could be a confusing term; would alwaysSupplyParameter be another possibility? Happy leaving the final choice of name in your hands, can move forward with this as soon as you're ready 👍

@srogovtsev
Copy link
Author

Here you have it. Sorry for the delay, we seem to be working from quite different time zones.

Just for the reference, I've decided to explicitly exclude ProvidedInstanceActivator, because in my opinion there's no way one can consume the logger we'd provide.

@srogovtsev srogovtsev marked this pull request as ready for review July 4, 2020 08:45
@nblumhardt nblumhardt merged commit cf020c2 into nblumhardt:dev Jul 6, 2020
@nblumhardt
Copy link
Owner

Fantastic PR - many thanks. I'll queue up a release PR to merge once the dev package has been in circulation for a litte while 👍

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.

2 participants