forked from PrismLibrary/Prism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure transient reuse irrespective of default reuse setting.
- Loading branch information
Showing
5 changed files
with
96 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
tests/Containers/Prism.Container.DryIoc.Tests/ContainerSetupWithDefaultSingleton.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using DryIoc; | ||
using Prism.DryIoc; | ||
using Prism.Ioc.Tests; | ||
|
||
namespace Prism.Ioc.DryIoc.Tests | ||
{ | ||
public class ContainerSetupWithDefaultSingleton : ContainerSetup | ||
{ | ||
public static Rules RulesWithDefaultSingleton => DryIocContainerExtension.DefaultRules.WithDefaultReuse(Reuse.Singleton); | ||
|
||
protected override IContainerExtension CreateContainerInternal() => new DryIocContainerExtension(new Container(RulesWithDefaultSingleton)); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
tests/Containers/Prism.Container.DryIoc.Tests/ContainerTestsWithDefaultSingleton.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using Prism.Ioc.Mocks.Services; | ||
using Prism.Ioc.Tests; | ||
using System; | ||
using Xunit; | ||
|
||
namespace Prism.Ioc.DryIoc.Tests | ||
{ | ||
public class ContainerTestsWithDefaultSingleton : IClassFixture<ContainerSetupWithDefaultSingleton>, IDisposable | ||
{ | ||
private bool disposedValue; | ||
|
||
protected ContainerSetup Setup { get; } | ||
|
||
public ContainerTestsWithDefaultSingleton(ContainerSetupWithDefaultSingleton setup) | ||
{ | ||
Setup = setup; | ||
} | ||
|
||
[Fact] | ||
public void RegisterServiceMappingCreatesTransient() | ||
{ | ||
var container = Setup.CreateContainer(); | ||
Setup.Registry.Register<IServiceA, ServiceA>(); | ||
var resolved1 = container.Resolve<IServiceA>(); | ||
var resolved2 = container.Resolve<IServiceA>(); | ||
Assert.NotNull(resolved1); | ||
Assert.NotNull(resolved2); | ||
Assert.IsType<ServiceA>(resolved1); | ||
Assert.IsType<ServiceA>(resolved2); | ||
Assert.NotSame(resolved1, resolved2); | ||
} | ||
|
||
[Fact] | ||
public void RegisterNamedServiceMappingCreatesTransient() | ||
{ | ||
var container = Setup.CreateContainer(); | ||
Setup.Registry.Register<IServiceA, ServiceA>("Test"); | ||
var resolved1 = container.Resolve<IServiceA>("Test"); | ||
var resolved2 = container.Resolve<IServiceA>("Test"); | ||
var ex = Record.Exception(() => container.Resolve<IServiceA>()); | ||
Assert.NotNull(ex); | ||
Assert.NotNull(resolved1); | ||
Assert.NotNull(resolved2); | ||
Assert.IsType<ServiceA>(resolved1); | ||
Assert.IsType<ServiceA>(resolved2); | ||
Assert.NotSame(resolved1, resolved2); | ||
} | ||
|
||
[Fact] | ||
public void AutomaticTransientResolutionOfConcreteType() | ||
{ | ||
var container = Setup.CreateContainer(); | ||
var resolved1 = container.Resolve<ServiceA>(); | ||
var resolved2 = container.Resolve<ServiceA>(); | ||
Assert.NotNull(resolved1); | ||
Assert.NotSame(resolved1, resolved2); | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (!disposedValue) | ||
{ | ||
if (disposing) | ||
{ | ||
Setup.Dispose(); | ||
} | ||
|
||
disposedValue = true; | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(disposing: true); | ||
GC.SuppressFinalize(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters