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

Automatically perform verification upon first resolve #555

Open
dotnetjunkie opened this Issue May 12, 2018 · 3 comments

Comments

3 participants
@dotnetjunkie
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 = false; // default true

container.Register<IFoo, FooImpl>();

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

This is, however, 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
@TheBigRic

This comment has been minimized.

Collaborator

TheBigRic commented May 15, 2018

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

This comment has been minimized.

Tornhoof commented Jun 5, 2018

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

@TheBigRic

This comment has been minimized.

Collaborator

TheBigRic commented Jun 10, 2018

@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 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment