Skip to content

Commit

Permalink
Container is now verified on first resolve. Fixes #747.
Browse files Browse the repository at this point in the history
  • Loading branch information
dotnetjunkie committed May 28, 2020
1 parent e0efef2 commit 0df6625
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ public void InterceptWithGenericArgAndPredicate_InterceptingATransientWithSingle

container.Register<ICommand, FakeCommand>();

container.Register<FakeInterceptor>(Lifestyle.Singleton);

container.InterceptWith<FakeInterceptor>(IsACommandPredicate);
container.InterceptWith<FakeInterceptor>(Lifestyle.Singleton, IsACommandPredicate);

// Act
var command1 = container.GetInstance<ICommand>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public void GetInstance_UnregisteredConcreteTypeWithNoPublicConstructors_ThrowsE
private static Container CreateContainerWithMostParametersConstructorResolutionBehavior()
{
var container = new Container();
container.Options.EnableAutoVerification = false;

container.Options.ConstructorResolutionBehavior = new MostParametersConstructorResolutionBehavior();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ public void GetInstance_WithinAAsyncScopedLifestyle_NeverDisposesASingleton()
{
// Arrange
var container = new Container();
container.Options.EnableAutoVerification = false;

container.Register<DisposableCommand>(Lifestyle.Singleton);

Expand Down Expand Up @@ -780,6 +781,7 @@ public void AsyncScopedLifestyleDispose_WithTransientRegisteredForDisposal_Dispo
DisposableCommand transientInstanceToDispose = null;

var container = new Container();
container.Options.EnableAutoVerification = false;

var lifestyle = new AsyncScopedLifestyle();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ public void LifetimeScopeDispose_WithTransientRegisteredForDisposal_DisposesThat
DisposableCommand transientInstanceToDispose = null;

var container = new Container();
container.Options.EnableAutoVerification = false;

container.Register<DisposableCommand>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void GetInstance_OnUnregisteredConcreteTypeWithoutDependencies_CallsInsta
int actualCallCount = 0;

var container = new Container();
container.Options.EnableAutoVerification = false;

container.Register<RealTimeProvider>();
container.RegisterInitializer(context => actualCallCount++, TruePredicate);
Expand Down Expand Up @@ -90,6 +91,7 @@ public void GetInstance_CalledOnInitializerWithPredicateReturningTrue_CallsPredi
int actualPredicateCallCount = 0;

var container = new Container();
container.Options.EnableAutoVerification = false;

container.Register<RealTimeProvider>();
container.RegisterInitializer(context => actualCallCount++, context =>
Expand Down Expand Up @@ -118,6 +120,7 @@ public void GetInstance_CalledTwiceOnUnregisteredConcreteTypeWithoutDependencies
int actualCallCount = 0;

var container = new Container();
container.Options.EnableAutoVerification = false;

container.Register<RealTimeProvider>();
container.RegisterInitializer(context => actualCallCount++, TruePredicate);
Expand Down Expand Up @@ -158,6 +161,7 @@ public void GetInstance_OnUnregisteredConcreteTypeWithoutDependencies_CallsInsta
var actualContexts = new List<InstanceInitializationData>();

var container = new Container();
container.Options.EnableAutoVerification = false;

container.Register<RealTimeProvider>();
container.RegisterInitializer(actualContexts.Add, TruePredicate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public void GetInstance_IEnumerable_InterceptsThatEnumerable()
var expectedInterceptedTypes = new[] { typeof(IEnumerable<ITimeProvider>) };

var container = new Container();
container.Options.EnableAutoVerification = false;

var contexts = new List<InitializationContext>();

Expand Down Expand Up @@ -255,6 +256,7 @@ public void GetInstance_ICollection_InterceptsThatCollection()
};

var container = new Container();
container.Options.EnableAutoVerification = false;

var contexts = new List<InitializationContext>();

Expand Down
4 changes: 2 additions & 2 deletions src/SimpleInjector/ContainerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ public bool UseStrictLifestyleMismatchBehavior
/// Gets or sets a value indicating whether the container should automatically trigger verification
/// and diagnostics of its configuration when the first service is resolved (e.g. the first call to
/// GetInstance). The behavior is identical to calling <see cref="Container.Verify()">Verify()</see>
/// manually. The default is false.
/// manually. The default is <b>true</b>.
/// </summary>
/// <value>The value indicating whether the container should automatically trigger verification.</value>
public bool EnableAutoVerification { get; set; }
public bool EnableAutoVerification { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether all the containers in the current AppDomain should throw
Expand Down

0 comments on commit 0df6625

Please sign in to comment.