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

Allow performing verification upon first resolve #555

Closed
dotnetjunkie opened this issue May 12, 2018 · 5 comments
Closed

Allow performing verification upon first resolve #555

dotnetjunkie opened this issue May 12, 2018 · 5 comments

Comments

@dotnetjunkie
Copy link
Collaborator

dotnetjunkie commented May 12, 2018

Many inexperienced users forget to call Verify() after configuring the container. To make it easier to do the right thing, we should consider automatically calling Verify() when the first service is resolved, in case the user didn't call it.

Since verification can cause performance problems for big applications, auto-verification should be configurable, for instance:

var container = new Container();
container.Options.EnableAutoVerification = true; // default false in v4.x

container.Register<IFoo, FooImpl>();

container.GetInstance<IFoo>(); // will trigger verification when EnableAutoVerification = true

Having the feature enabled by default, however, is a major breaking change, because in case the user upgrades to this new version, without setting EnableAutoVerification to false, it will cause the container to be verified, even though the user might explicitly prevented this in his production environment:

#if DEBUG
    // Prevent verification in release mode.
    container.Verify();
#endif

In v4 the feature can be added, as long as it is off by default.

@TheBigRic
Copy link
Collaborator

I'm tempted to react with thumbs up because verification is something which separates Simple Injector from the rest and is also some kind of ultra climax of all design principles.

However. I think the impact of the breaking change is huge and maybe too huge!

Maybe there is an elegant solution which could be used in two ways. What do you think of including a .ps script in the NuGet package which generates some commented code? This could be both

container.Verify();

and

container.Options.EnableAutoVerification = true;

of course shipped as a more or less complete bootstrapper.cs/bootstrapper.vb

@Tornhoof
Copy link

Tornhoof commented Jun 5, 2018

@TheBigRic nuget references can't use install.ps1 anymore. So this only works for the legacy references.

@TheBigRic
Copy link
Collaborator

@Tornhoof
Ok, good to know this is not supported anymore. However, what install.ps1 was meant to do as a feature is still there although somewhat different.

At this time it is probably more interesting to decide which path to take with this, to auto verify or not to auto verify, that's the question :-)

@dotnetjunkie
Copy link
Collaborator Author

feature-555 branch created.

@dotnetjunkie dotnetjunkie changed the title Automatically perform verification upon first resolve Allow performing verification upon first resolve Sep 26, 2019
@dotnetjunkie
Copy link
Collaborator Author

@davidroth I was trying to find out what the counter arguments would be for implementing this feature, as I now started working on implementing it. I suspect you downvoted because this feature was initially described as a breaking change (which it still is, but the breaking part is moved to #747). The issue has been updated several times, so it's very well possible that it was confusing to begin with.

dotnetjunkie added a commit that referenced this issue Oct 1, 2019
…toVerification will be set to true by default. #555
dotnetjunkie added a commit that referenced this issue Nov 24, 2019
…toVerification will be set to true by default. #555
Repository owner deleted a comment from davidroth Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants