simpleinjector / SimpleInjector

An easy, flexible, and fast Dependency Injection library that promotes best practice to steer developers towards the pit of success.
https://simpleinjector.org
MIT License
1.22k stars 152 forks source link

Auto verification cannot be turned off #854

Closed gitcob closed 4 years ago

gitcob commented 4 years ago

The EnableAutoVerification option does not seem to do anything.

Here is an xUnit test case:

public class MyClass { }

[Fact]
public void ResolveBeforeVerifyFailsWhenAutoVerificationIsDisabled()
{
    using var container = new Container { Options = { EnableAutoVerification = false } };
    container.Register<MyClass>();

    Assert.Throws<ActivationException>(() => container.GetInstance<MyClass>());
}

Found in nuget version 5.0.3.

dotnetjunkie commented 4 years ago

That's correct. When set to true (the default) EnableAutoVerification will ensure verification on first resolve. When set to false (as your example) nothing happens. There's more information about auto verification in the documentation.

gitcob commented 4 years ago

I see, then I misunderstood the v5 release notes. I thought setting it to false would trigger the old behavior - if I recall correctly, it used to throw an exception if you tried to resolve before verifying.