diff --git a/dependency-injection-tools/SimpleInjectorImplementationConsole/SimpleInjectorExample/ContainerManager.cs b/dependency-injection-tools/SimpleInjectorImplementationConsole/SimpleInjectorExample/ContainerManager.cs index fee97a39e9..ee22dce206 100644 --- a/dependency-injection-tools/SimpleInjectorImplementationConsole/SimpleInjectorExample/ContainerManager.cs +++ b/dependency-injection-tools/SimpleInjectorImplementationConsole/SimpleInjectorExample/ContainerManager.cs @@ -5,7 +5,7 @@ public class ContainerManager { - private static readonly Lazy _container = new Lazy(ConfigureServices); + private static readonly Lazy _container = new(ConfigureServices); private static Container ConfigureServices() { @@ -20,5 +20,5 @@ private static Container ConfigureServices() return container; } - public static Container Instance { get => _container.Value; } + public static Container Instance => _container.Value; } \ No newline at end of file diff --git a/dependency-injection-tools/SimpleInjectorImplementationConsole/SimpleInjectorExample/SimpleInjectorExample.csproj b/dependency-injection-tools/SimpleInjectorImplementationConsole/SimpleInjectorExample/SimpleInjectorExample.csproj index 19510f087b..01bb0d8fc4 100644 --- a/dependency-injection-tools/SimpleInjectorImplementationConsole/SimpleInjectorExample/SimpleInjectorExample.csproj +++ b/dependency-injection-tools/SimpleInjectorImplementationConsole/SimpleInjectorExample/SimpleInjectorExample.csproj @@ -1,11 +1,11 @@ Exe - net6.0 + net10.0 enable enable - + \ No newline at end of file diff --git a/dependency-injection-tools/SimpleInjectorImplementationConsole/Tests/ContainerManagerTests.cs b/dependency-injection-tools/SimpleInjectorImplementationConsole/Tests/ContainerManagerTests.cs index ef5b82b5b8..ee8964ba80 100644 --- a/dependency-injection-tools/SimpleInjectorImplementationConsole/Tests/ContainerManagerTests.cs +++ b/dependency-injection-tools/SimpleInjectorImplementationConsole/Tests/ContainerManagerTests.cs @@ -1,6 +1,7 @@ using SimpleInjectorExample.Services; using SimpleInjectorExample.Spec; +using SimpleInjector; using SimpleInjector.Lifestyles; namespace Tests; @@ -64,4 +65,18 @@ public void GivenIUserService_WhenGetInstanceIsInvoked_ThenReturnsUserService() Assert.Equal(expectedType,service.GetType()); } -} \ No newline at end of file + [Fact] + public void GivenSingletonDependingOnScoped_WhenVerifyIsInvoked_ThenThrowsLifestyleMismatch() + { + var container = new Container(); + container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle(); + container.Register(Lifestyle.Singleton); + container.Register(Lifestyle.Scoped); + container.Register(Lifestyle.Singleton); + + var exception = Assert.Throws(() => container.Verify()); + + Assert.Contains("[Lifestyle Mismatch]", exception.Message); + } + +} diff --git a/dependency-injection-tools/SimpleInjectorImplementationConsole/Tests/Tests.csproj b/dependency-injection-tools/SimpleInjectorImplementationConsole/Tests/Tests.csproj index 26d403e987..7727c79421 100644 --- a/dependency-injection-tools/SimpleInjectorImplementationConsole/Tests/Tests.csproj +++ b/dependency-injection-tools/SimpleInjectorImplementationConsole/Tests/Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + net10.0 enable enable @@ -9,13 +9,13 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all