diff --git a/Directory.Packages.props b/Directory.Packages.props index c1b4283eda..be9aba98a4 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,7 +1,8 @@ - - + + + @@ -52,14 +53,14 @@ - + - - - - + + + + diff --git a/PrismLibrary.sln b/PrismLibrary.sln index c16390cab7..468c1fa15d 100644 --- a/PrismLibrary.sln +++ b/PrismLibrary.sln @@ -59,24 +59,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.DI.Forms.Tests", "tests\Forms\Prism.DI.Forms.Tests\Prism.DI.Forms.Tests.shproj", "{FAC4FA5A-D6C1-4787-9B1F-A3EC6E2FB26E}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Containers", "Containers", "{75B1C655-8365-4130-8B79-C748BF0403F2}" -EndProject -Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.Unity.Shared", "src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.shproj", "{D66336A6-07E5-401A-A710-DAEDD6975D59}" -EndProject -Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.DryIoc.Shared", "src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.shproj", "{6E7EC81D-DA39-4C4F-A898-0148558C34F4}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Uno", "Uno", "{8F959801-D494-4CAF-9437-90F30472E169}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Forms.Regions", "src\Forms\Prism.Forms.Regions\Prism.Forms.Regions.csproj", "{7760BB71-219E-4DB1-B67C-7A428D9A10E2}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Ioc.DryIoc.Tests", "tests\Containers\Prism.Container.DryIoc.Tests\Prism.Ioc.DryIoc.Tests.csproj", "{2D7EC81A-17B5-47C3-8AE1-619F7F8843AA}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Ioc.Unity.Tests", "tests\Containers\Prism.Container.Unity.Tests\Prism.Ioc.Unity.Tests.csproj", "{704E14A4-C3A2-492D-9C4E-7D386A18B698}" -EndProject -Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.Ioc.Shared", "tests\Containers\Prism.Container.Shared\Prism.Ioc.Shared.shproj", "{78932299-2281-4A59-BFB8-07DE3014F748}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Containers", "Containers", "{D62DD517-CA80-449D-A26B-9AB427379825}" -EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.Container.Wpf.Shared", "tests\Wpf\Prism.Container.Wpf.Shared\Prism.Container.Wpf.Shared.shproj", "{BD42A7D6-A84D-4D27-9C28-7F6A2EC477F1}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Uno.WinUI", "src\Uno\Prism.Uno\Prism.Uno.WinUI.csproj", "{E74664C1-1BB1-4920-8099-2C9125CFD00B}" @@ -99,7 +85,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Maui.Tests", "tests\M EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.DryIoc.Maui.Tests", "tests\Maui\Prism.DryIoc.Maui.Tests\Prism.DryIoc.Maui.Tests.csproj", "{8711D306-1118-4A11-9399-EF14AA13015E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Prism.Events", "src\Prism.Events\Prism.Events.csproj", "{8610485A-BE9F-4938-86D4-E9F1FA1739A0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Events", "src\Prism.Events\Prism.Events.csproj", "{8610485A-BE9F-4938-86D4-E9F1FA1739A0}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -303,30 +289,6 @@ Global {7760BB71-219E-4DB1-B67C-7A428D9A10E2}.Release|x64.Build.0 = Release|Any CPU {7760BB71-219E-4DB1-B67C-7A428D9A10E2}.Release|x86.ActiveCfg = Release|Any CPU {7760BB71-219E-4DB1-B67C-7A428D9A10E2}.Release|x86.Build.0 = Release|Any CPU - {2D7EC81A-17B5-47C3-8AE1-619F7F8843AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2D7EC81A-17B5-47C3-8AE1-619F7F8843AA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2D7EC81A-17B5-47C3-8AE1-619F7F8843AA}.Debug|x64.ActiveCfg = Debug|Any CPU - {2D7EC81A-17B5-47C3-8AE1-619F7F8843AA}.Debug|x64.Build.0 = Debug|Any CPU - {2D7EC81A-17B5-47C3-8AE1-619F7F8843AA}.Debug|x86.ActiveCfg = Debug|Any CPU - {2D7EC81A-17B5-47C3-8AE1-619F7F8843AA}.Debug|x86.Build.0 = Debug|Any CPU - {2D7EC81A-17B5-47C3-8AE1-619F7F8843AA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2D7EC81A-17B5-47C3-8AE1-619F7F8843AA}.Release|Any CPU.Build.0 = Release|Any CPU - {2D7EC81A-17B5-47C3-8AE1-619F7F8843AA}.Release|x64.ActiveCfg = Release|Any CPU - {2D7EC81A-17B5-47C3-8AE1-619F7F8843AA}.Release|x64.Build.0 = Release|Any CPU - {2D7EC81A-17B5-47C3-8AE1-619F7F8843AA}.Release|x86.ActiveCfg = Release|Any CPU - {2D7EC81A-17B5-47C3-8AE1-619F7F8843AA}.Release|x86.Build.0 = Release|Any CPU - {704E14A4-C3A2-492D-9C4E-7D386A18B698}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {704E14A4-C3A2-492D-9C4E-7D386A18B698}.Debug|Any CPU.Build.0 = Debug|Any CPU - {704E14A4-C3A2-492D-9C4E-7D386A18B698}.Debug|x64.ActiveCfg = Debug|Any CPU - {704E14A4-C3A2-492D-9C4E-7D386A18B698}.Debug|x64.Build.0 = Debug|Any CPU - {704E14A4-C3A2-492D-9C4E-7D386A18B698}.Debug|x86.ActiveCfg = Debug|Any CPU - {704E14A4-C3A2-492D-9C4E-7D386A18B698}.Debug|x86.Build.0 = Debug|Any CPU - {704E14A4-C3A2-492D-9C4E-7D386A18B698}.Release|Any CPU.ActiveCfg = Release|Any CPU - {704E14A4-C3A2-492D-9C4E-7D386A18B698}.Release|Any CPU.Build.0 = Release|Any CPU - {704E14A4-C3A2-492D-9C4E-7D386A18B698}.Release|x64.ActiveCfg = Release|Any CPU - {704E14A4-C3A2-492D-9C4E-7D386A18B698}.Release|x64.Build.0 = Release|Any CPU - {704E14A4-C3A2-492D-9C4E-7D386A18B698}.Release|x86.ActiveCfg = Release|Any CPU - {704E14A4-C3A2-492D-9C4E-7D386A18B698}.Release|x86.Build.0 = Release|Any CPU {E74664C1-1BB1-4920-8099-2C9125CFD00B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E74664C1-1BB1-4920-8099-2C9125CFD00B}.Debug|Any CPU.Build.0 = Debug|Any CPU {E74664C1-1BB1-4920-8099-2C9125CFD00B}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -460,15 +422,8 @@ Global {367BE810-5B34-4894-BE47-1C8DCC67DE81} = {F1F91777-01EA-43A3-A3ED-D473B382F46C} {2E8F565D-9D13-424E-BD86-C5A362F9AAE7} = {F1F91777-01EA-43A3-A3ED-D473B382F46C} {FAC4FA5A-D6C1-4787-9B1F-A3EC6E2FB26E} = {F8A0FDE6-8E75-47D1-9E33-02AB8E8AB473} - {75B1C655-8365-4130-8B79-C748BF0403F2} = {F3664D7A-6FF5-4D1F-9F5F-26EE87F032D3} - {D66336A6-07E5-401A-A710-DAEDD6975D59} = {75B1C655-8365-4130-8B79-C748BF0403F2} - {6E7EC81D-DA39-4C4F-A898-0148558C34F4} = {75B1C655-8365-4130-8B79-C748BF0403F2} {8F959801-D494-4CAF-9437-90F30472E169} = {F3664D7A-6FF5-4D1F-9F5F-26EE87F032D3} {7760BB71-219E-4DB1-B67C-7A428D9A10E2} = {017675AD-346B-499D-819A-C43A2288DE98} - {2D7EC81A-17B5-47C3-8AE1-619F7F8843AA} = {D62DD517-CA80-449D-A26B-9AB427379825} - {704E14A4-C3A2-492D-9C4E-7D386A18B698} = {D62DD517-CA80-449D-A26B-9AB427379825} - {78932299-2281-4A59-BFB8-07DE3014F748} = {D62DD517-CA80-449D-A26B-9AB427379825} - {D62DD517-CA80-449D-A26B-9AB427379825} = {00FFDC13-7397-46F1-897E-A62A7575D28A} {BD42A7D6-A84D-4D27-9C28-7F6A2EC477F1} = {F1F91777-01EA-43A3-A3ED-D473B382F46C} {E74664C1-1BB1-4920-8099-2C9125CFD00B} = {8F959801-D494-4CAF-9437-90F30472E169} {DB530D15-0556-4B6F-96B2-1497C8DF08D6} = {8F959801-D494-4CAF-9437-90F30472E169} @@ -487,23 +442,10 @@ Global EndGlobalSection GlobalSection(SharedMSBuildProjectFiles) = preSolution tests\Forms\Prism.DI.Forms.Tests\Prism.DI.Forms.Tests.projitems*{089c5e84-52c3-409e-924c-bd8f4833594b}*SharedItemsImports = 5 - src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.projitems*{0c8aab85-387c-41d2-abce-bafaf74b62b2}*SharedItemsImports = 5 - src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.projitems*{2d7ec81a-17b5-47c3-8ae1-619f7f8843aa}*SharedItemsImports = 5 - tests\Containers\Prism.Container.Shared\Prism.Container.Shared.projitems*{2d7ec81a-17b5-47c3-8ae1-619f7f8843aa}*SharedItemsImports = 5 tests\Wpf\Prism.Container.Wpf.Shared\Prism.Container.Wpf.Shared.projitems*{367be810-5b34-4894-be47-1c8dcc67de81}*SharedItemsImports = 5 - src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.projitems*{60d92138-66ac-4dc9-973d-fdd917f87112}*SharedItemsImports = 5 - src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.projitems*{6e7ec81d-da39-4c4f-a898-0148558c34f4}*SharedItemsImports = 13 - src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.projitems*{704e14a4-c3a2-492d-9c4e-7d386a18b698}*SharedItemsImports = 5 - tests\Containers\Prism.Container.Shared\Prism.Container.Shared.projitems*{704e14a4-c3a2-492d-9c4e-7d386a18b698}*SharedItemsImports = 5 - tests\Containers\Prism.Container.Shared\Prism.Container.Shared.projitems*{78932299-2281-4a59-bfb8-07de3014f748}*SharedItemsImports = 13 - src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.projitems*{aad8a958-546b-4b7d-bbd1-d79e825530eb}*SharedItemsImports = 5 tests\Wpf\Prism.Container.Wpf.Shared\Prism.Container.Wpf.Shared.projitems*{ba05687e-2317-4a65-805b-c596f52f7203}*SharedItemsImports = 5 tests\Wpf\Prism.Container.Wpf.Shared\Prism.Container.Wpf.Shared.projitems*{bd42a7d6-a84d-4d27-9c28-7f6a2ec477f1}*SharedItemsImports = 13 - src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.projitems*{c2f58215-92f0-4501-a9f4-862c78b2b4ce}*SharedItemsImports = 5 tests\Forms\Prism.DI.Forms.Tests\Prism.DI.Forms.Tests.projitems*{c2ff8459-f2d1-4b87-a31a-82a1835f89cf}*SharedItemsImports = 5 - src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.projitems*{d66336a6-07e5-401a-a710-daedd6975d59}*SharedItemsImports = 13 - src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.projitems*{db530d15-0556-4b6f-96b2-1497c8df08d6}*SharedItemsImports = 5 - src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.projitems*{e9a2458b-999d-4d36-822f-663d3830575a}*SharedItemsImports = 5 tests\Forms\Prism.DI.Forms.Tests\Prism.DI.Forms.Tests.projitems*{fac4fa5a-d6c1-4787-9b1f-a3ec6e2fb26e}*SharedItemsImports = 13 EndGlobalSection EndGlobal diff --git a/PrismLibrary_Core.slnf b/PrismLibrary_Core.slnf index d870bc04cf..5cbb22b6ee 100644 --- a/PrismLibrary_Core.slnf +++ b/PrismLibrary_Core.slnf @@ -2,13 +2,8 @@ "solution": { "path": "PrismLibrary.sln", "projects": [ - "src\\Containers\\Prism.DryIoc.Shared\\Prism.DryIoc.Shared.shproj", - "src\\Containers\\Prism.Unity.Shared\\Prism.Unity.Shared.shproj", "src\\Prism.Core\\Prism.Core.csproj", "src\\Prism.Events\\Prism.Events.csproj", - "tests\\Containers\\Prism.Container.DryIoc.Tests\\Prism.Ioc.DryIoc.Tests.csproj", - "tests\\Containers\\Prism.Container.Shared\\Prism.Ioc.Shared.shproj", - "tests\\Containers\\Prism.Container.Unity.Tests\\Prism.Ioc.Unity.Tests.csproj", "tests\\Prism.Core.Tests\\Prism.Core.Tests.csproj" ] } diff --git a/PrismLibrary_Forms.slnf b/PrismLibrary_Forms.slnf index 42c38975c8..4c22eebec8 100644 --- a/PrismLibrary_Forms.slnf +++ b/PrismLibrary_Forms.slnf @@ -2,17 +2,12 @@ "solution": { "path": "PrismLibrary.sln", "projects": [ - "src\\Containers\\Prism.DryIoc.Shared\\Prism.DryIoc.Shared.shproj", - "src\\Containers\\Prism.Unity.Shared\\Prism.Unity.Shared.shproj", "src\\Forms\\Prism.DryIoc.Forms\\Prism.DryIoc.Forms.csproj", "src\\Forms\\Prism.Forms.Regions\\Prism.Forms.Regions.csproj", "src\\Forms\\Prism.Forms\\Prism.Forms.csproj", "src\\Forms\\Prism.Unity.Forms\\Prism.Unity.Forms.csproj", "src\\Prism.Core\\Prism.Core.csproj", "src\\Prism.Events\\Prism.Events.csproj", - "tests\\Containers\\Prism.Container.DryIoc.Tests\\Prism.Ioc.DryIoc.Tests.csproj", - "tests\\Containers\\Prism.Container.Shared\\Prism.Ioc.Shared.shproj", - "tests\\Containers\\Prism.Container.Unity.Tests\\Prism.Ioc.Unity.Tests.csproj", "tests\\Forms\\Prism.DI.Forms.Tests\\Prism.DI.Forms.Tests.shproj", "tests\\Forms\\Prism.DryIoc.Forms.Tests\\Prism.DryIoc.Forms.Tests.csproj", "tests\\Forms\\Prism.Forms.Regions.Tests\\Prism.Forms.Regions.Tests.csproj", diff --git a/PrismLibrary_Maui.slnf b/PrismLibrary_Maui.slnf index 0248af8dfc..0ef9a20368 100644 --- a/PrismLibrary_Maui.slnf +++ b/PrismLibrary_Maui.slnf @@ -2,14 +2,11 @@ "solution": { "path": "PrismLibrary.sln", "projects": [ - "src\\Containers\\Prism.DryIoc.Shared\\Prism.DryIoc.Shared.shproj", "src\\Maui\\Prism.DryIoc.Maui\\Prism.DryIoc.Maui.csproj", "src\\Maui\\Prism.Maui.Rx\\Prism.Maui.Rx.csproj", "src\\Maui\\Prism.Maui\\Prism.Maui.csproj", "src\\Prism.Core\\Prism.Core.csproj", "src\\Prism.Events\\Prism.Events.csproj", - "tests\\Containers\\Prism.Container.DryIoc.Tests\\Prism.Ioc.DryIoc.Tests.csproj", - "tests\\Containers\\Prism.Container.Shared\\Prism.Ioc.Shared.shproj", "tests\\Maui\\Prism.DryIoc.Maui.Tests\\Prism.DryIoc.Maui.Tests.csproj", "tests\\Maui\\Prism.Maui.Tests\\Prism.Maui.Tests.csproj", "tests\\Prism.Core.Tests\\Prism.Core.Tests.csproj" diff --git a/PrismLibrary_Uno.slnf b/PrismLibrary_Uno.slnf index 3438a423d2..3c69accf58 100644 --- a/PrismLibrary_Uno.slnf +++ b/PrismLibrary_Uno.slnf @@ -2,15 +2,10 @@ "solution": { "path": "PrismLibrary.sln", "projects": [ - "src\\Containers\\Prism.DryIoc.Shared\\Prism.DryIoc.Shared.shproj", - "src\\Containers\\Prism.Unity.Shared\\Prism.Unity.Shared.shproj", "src\\Prism.Core\\Prism.Core.csproj", "src\\Prism.Events\\Prism.Events.csproj", "src\\Uno\\Prism.DryIoc.Uno\\Prism.DryIoc.Uno.WinUI.csproj", "src\\Uno\\Prism.Uno\\Prism.Uno.WinUI.csproj", - "tests\\Containers\\Prism.Container.DryIoc.Tests\\Prism.Ioc.DryIoc.Tests.csproj", - "tests\\Containers\\Prism.Container.Shared\\Prism.Ioc.Shared.shproj", - "tests\\Containers\\Prism.Container.Unity.Tests\\Prism.Ioc.Unity.Tests.csproj", "tests\\Prism.Core.Tests\\Prism.Core.Tests.csproj" ] } diff --git a/PrismLibrary_Wpf.slnf b/PrismLibrary_Wpf.slnf index b988d35c28..8ff6843d98 100644 --- a/PrismLibrary_Wpf.slnf +++ b/PrismLibrary_Wpf.slnf @@ -2,16 +2,11 @@ "solution": { "path": "PrismLibrary.sln", "projects": [ - "src\\Containers\\Prism.DryIoc.Shared\\Prism.DryIoc.Shared.shproj", - "src\\Containers\\Prism.Unity.Shared\\Prism.Unity.Shared.shproj", "src\\Prism.Core\\Prism.Core.csproj", "src\\Prism.Events\\Prism.Events.csproj", "src\\Wpf\\Prism.DryIoc.Wpf\\Prism.DryIoc.Wpf.csproj", "src\\Wpf\\Prism.Unity.Wpf\\Prism.Unity.Wpf.csproj", "src\\Wpf\\Prism.Wpf\\Prism.Wpf.csproj", - "tests\\Containers\\Prism.Container.DryIoc.Tests\\Prism.Ioc.DryIoc.Tests.csproj", - "tests\\Containers\\Prism.Container.Shared\\Prism.Ioc.Shared.shproj", - "tests\\Containers\\Prism.Container.Unity.Tests\\Prism.Ioc.Unity.Tests.csproj", "tests\\Prism.Core.Tests\\Prism.Core.Tests.csproj", "tests\\Wpf\\Prism.Container.Wpf.Shared\\Prism.Container.Wpf.Shared.shproj", "tests\\Wpf\\Prism.DryIoc.Wpf.Tests\\Prism.DryIoc.Wpf.Tests.csproj", diff --git a/src/Containers/Prism.DryIoc.Shared/DryIocContainerExtension.cs b/src/Containers/Prism.DryIoc.Shared/DryIocContainerExtension.cs deleted file mode 100644 index 666f2539d9..0000000000 --- a/src/Containers/Prism.DryIoc.Shared/DryIocContainerExtension.cs +++ /dev/null @@ -1,452 +0,0 @@ -using System; -using System.Linq; -using DryIoc; -using Prism.Ioc; -using Prism.Ioc.Internals; -using ExceptionExtensions = System.ExceptionExtensions; -using IContainer = DryIoc.IContainer; - -namespace Prism.DryIoc -{ - /// - /// The Implementation to use with DryIoc - /// -#if ContainerExtensions - internal -#else - public -#endif - partial class DryIocContainerExtension : IContainerExtension, IContainerInfo - { - private DryIocScopedProvider _currentScope; - - /// - /// Gets the Default DryIoc Container Rules used by Prism - /// - public static Rules DefaultRules => Rules.Default.WithConcreteTypeDynamicRegistrations(reuse: Reuse.Transient) - .With(Made.Of(FactoryMethod.ConstructorWithResolvableArguments)) - .WithFuncAndLazyWithoutRegistration() - .WithTrackingDisposableTransients() - // .WithoutFastExpressionCompiler() - .WithFactorySelector(Rules.SelectLastRegisteredFactory()); - - /// - /// The instance of the wrapped container - /// - public IContainer Instance { get; } - -#if !ContainerExtensions - /// - /// Constructs a default instance of the - /// - public DryIocContainerExtension() - : this(DefaultRules) - { - } - - public DryIocContainerExtension(Rules rules) - : this(new Container(rules)) - { - } - - /// - /// Constructs a new - /// - /// The instance to use. - public DryIocContainerExtension(IContainer container) - { - Instance = container; - Instance.RegisterInstanceMany(new[] - { - typeof(IContainerExtension), - typeof(IContainerProvider) - }, this); - ExceptionExtensions.RegisterFrameworkExceptionType(typeof(ContainerException)); - } -#endif - - /// - /// Gets the current scope - /// - public IScopedProvider CurrentScope => _currentScope; - - /// - /// Used to perform any final steps for configuring the extension that may be required by the container. - /// - public void FinalizeExtension() { } - - /// - /// Registers an instance of a given - /// - /// The service that is being registered - /// The instance of the service or - /// The instance - public IContainerRegistry RegisterInstance(Type type, object instance) - { - Instance.RegisterInstance(type, instance); - return this; - } - - /// - /// Registers an instance of a given with the specified name or key - /// - /// The service that is being registered - /// The instance of the service or - /// The name or key to register the service - /// The instance - public IContainerRegistry RegisterInstance(Type type, object instance, string name) - { - Instance.RegisterInstance(type, instance, ifAlreadyRegistered: IfAlreadyRegistered.Replace, serviceKey: name); - return this; - } - - /// - /// Registers a Singleton with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The instance - public IContainerRegistry RegisterSingleton(Type from, Type to) - { - Instance.Register(from, to, Reuse.Singleton); - return this; - } - - /// - /// Registers a Singleton with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The name or key to register the service - /// The instance - public IContainerRegistry RegisterSingleton(Type from, Type to, string name) - { - Instance.Register(from, to, Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Replace, serviceKey: name); - return this; - } - - /// - /// Registers a Singleton with the given service factory delegate method. - /// - /// The service - /// The delegate method. - /// The instance - public IContainerRegistry RegisterSingleton(Type type, Func factoryMethod) - { - Instance.RegisterDelegate(type, r => factoryMethod(), Reuse.Singleton); - return this; - } - - /// - /// Registers a Singleton with the given service factory delegate method. - /// - /// The service - /// The delegate method using . - /// The instance - public IContainerRegistry RegisterSingleton(Type type, Func factoryMethod) - { - Instance.RegisterDelegate(type, factoryMethod, Reuse.Singleton); - return this; - } - - /// - /// Registers a Singleton Service which implements service interfaces - /// - /// The implementation . - /// The service 's. - /// The instance - /// Registers all interfaces if none are specified. - public IContainerRegistry RegisterManySingleton(Type type, params Type[] serviceTypes) - { - if (serviceTypes.Length == 0) - { - serviceTypes = type.GetInterfaces(); - } - - Instance.RegisterMany(serviceTypes, type, Reuse.Singleton); - return this; - } - - /// - /// Registers a scoped service - /// - /// The service - /// The implementation - /// The instance - public IContainerRegistry RegisterScoped(Type from, Type to) - { - Instance.Register(from, to, Reuse.ScopedOrSingleton); - return this; - } - - /// - /// Registers a scoped service using a delegate method. - /// - /// The service - /// The delegate method. - /// The instance - public IContainerRegistry RegisterScoped(Type type, Func factoryMethod) - { - Instance.RegisterDelegate(type, r => factoryMethod(), Reuse.ScopedOrSingleton); - return this; - } - - /// - /// Registers a scoped service using a delegate method. - /// - /// The service . - /// The delegate method using the . - /// The instance - public IContainerRegistry RegisterScoped(Type type, Func factoryMethod) - { - Instance.RegisterDelegate(type, factoryMethod, Reuse.ScopedOrSingleton); - return this; - } - - /// - /// Registers a Transient with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The instance - public IContainerRegistry Register(Type from, Type to) - { - Instance.Register(from, to, Reuse.Transient); - return this; - } - - /// - /// Registers a Transient with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The name or key to register the service - /// The instance - public IContainerRegistry Register(Type from, Type to, string name) - { - Instance.Register(from, to, Reuse.Transient, ifAlreadyRegistered: IfAlreadyRegistered.Replace, serviceKey: name); - return this; - } - - /// - /// Registers a Transient Service using a delegate method - /// - /// The service - /// The delegate method. - /// The instance - public IContainerRegistry Register(Type type, Func factoryMethod) - { - Instance.RegisterDelegate(type, r => factoryMethod(), Reuse.Transient); - return this; - } - - /// - /// Registers a Transient Service using a delegate method - /// - /// The service - /// The delegate method using . - /// The instance - public IContainerRegistry Register(Type type, Func factoryMethod) - { - Instance.RegisterDelegate(type, factoryMethod, Reuse.Transient); - return this; - } - - /// - /// Registers a Transient Service which implements service interfaces - /// - /// The implementing . - /// The service 's. - /// The instance - /// Registers all interfaces if none are specified. - public IContainerRegistry RegisterMany(Type type, params Type[] serviceTypes) - { - if (serviceTypes.Length == 0) - { - serviceTypes = type.GetInterfaces(); - } - - Instance.RegisterMany(serviceTypes, type, Reuse.Transient); - return this; - } - - /// - /// Resolves a given - /// - /// The service - /// The resolved Service - public object Resolve(Type type) => - Resolve(type, Array.Empty<(Type, object)>()); - - /// - /// Resolves a given - /// - /// The service - /// The service name/key used when registering the - /// The resolved Service - public object Resolve(Type type, string name) => - Resolve(type, name, Array.Empty<(Type, object)>()); - - /// - /// Resolves a given - /// - /// The service - /// Typed parameters to use when resolving the Service - /// The resolved Service - public object Resolve(Type type, params (Type Type, object Instance)[] parameters) - { - try - { - var container = _currentScope?.Resolver ?? Instance; - var args = parameters.Where(x => x.Instance is not IContainerProvider) - .Select(x => x.Instance) - .ToList(); - args.Add(this); - return container.Resolve(type, args: args.ToArray()); - } - catch (Exception ex) - { - throw new ContainerResolutionException(type, ex, this); - } - } - - /// - /// Resolves a given - /// - /// The service - /// The service name/key used when registering the - /// Typed parameters to use when resolving the Service - /// The resolved Service - public object Resolve(Type type, string name, params (Type Type, object Instance)[] parameters) - { - try - { - var container = _currentScope?.Resolver ?? Instance; - var args = parameters.Where(x => x.Instance is not IContainerProvider) - .Select(x => x.Instance) - .ToList(); - args.Add(this); - return container.Resolve(type, name, args: args.ToArray()); - } - catch (Exception ex) - { - throw new ContainerResolutionException(type, name, ex, this); - } - } - - /// - /// Determines if a given service is registered - /// - /// The service - /// true if the service is registered. - public bool IsRegistered(Type type) - { - return Instance.IsRegistered(type); - } - - /// - /// Determines if a given service is registered with the specified name - /// - /// The service - /// The service name or key used - /// true if the service is registered. - public bool IsRegistered(Type type, string name) - { - return Instance.IsRegistered(type, name) || Instance.IsRegistered(type, name, FactoryType.Wrapper); ; - } - - Type IContainerInfo.GetRegistrationType(string key) - { - var matchingRegistration = Instance.GetServiceRegistrations().Where(r => key.Equals(r.OptionalServiceKey?.ToString(), StringComparison.Ordinal)).FirstOrDefault(); - if (matchingRegistration.OptionalServiceKey == null) - matchingRegistration = Instance.GetServiceRegistrations().Where(r => key.Equals(r.ImplementationType.Name, StringComparison.Ordinal)).FirstOrDefault(); - - return matchingRegistration.ImplementationType; - } - - Type IContainerInfo.GetRegistrationType(Type serviceType) - { - var registration = Instance.GetServiceRegistrations().Where(x => x.ServiceType == serviceType).FirstOrDefault(); - return registration.ServiceType is null ? null : registration.ImplementationType; - } - - /// - /// Creates a new Scope - /// - public virtual IScopedProvider CreateScope() => - CreateScopeInternal(); - - /// - /// Creates a new Scope and provides the updated ServiceProvider - /// - /// The Scoped . - /// - /// This should be called by custom implementations that Implement IServiceScopeFactory - /// - protected IScopedProvider CreateScopeInternal() - { - var resolver = Instance.OpenScope(); - _currentScope = new DryIocScopedProvider(resolver); - return _currentScope; - } - - private class DryIocScopedProvider : IScopedProvider - { - public DryIocScopedProvider(IResolverContext resolver) - { - Resolver = resolver; - } - - public bool IsAttached { get; set; } - - public IResolverContext Resolver { get; private set; } - public IScopedProvider CurrentScope => this; - - public IScopedProvider CreateScope() => new DryIocScopedProvider(Resolver.OpenScope()); - - public void Dispose() - { - Resolver.Dispose(); - Resolver = null; - } - - public object Resolve(Type type) => - Resolve(type, Array.Empty<(Type, object)>()); - - public object Resolve(Type type, string name) => - Resolve(type, name, Array.Empty<(Type, object)>()); - - public object Resolve(Type type, params (Type Type, object Instance)[] parameters) - { - try - { - var args = parameters.Where(x => x.Instance is not IContainerProvider) - .Select(x => x.Instance) - .ToList(); - args.Add(this); - return Resolver.Resolve(type, args: args.ToArray()); - } - catch (Exception ex) - { - throw new ContainerResolutionException(type, ex, this); - } - } - - public object Resolve(Type type, string name, params (Type Type, object Instance)[] parameters) - { - try - { - var args = parameters.Where(x => x.Instance is not IContainerProvider) - .Select(x => x.Instance) - .ToList(); - args.Add(this); - return Resolver.Resolve(type, name, args: args.ToArray()); - } - catch (Exception ex) - { - throw new ContainerResolutionException(type, name, ex, this); - } - } - } - } -} diff --git a/src/Containers/Prism.DryIoc.Shared/Prism.DryIoc.Shared.projitems b/src/Containers/Prism.DryIoc.Shared/Prism.DryIoc.Shared.projitems deleted file mode 100644 index 2536e87499..0000000000 --- a/src/Containers/Prism.DryIoc.Shared/Prism.DryIoc.Shared.projitems +++ /dev/null @@ -1,15 +0,0 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - true - 6e7ec81d-da39-4c4f-a898-0148558c34f4 - - - Prism.DryIoc - - - - - - \ No newline at end of file diff --git a/src/Containers/Prism.DryIoc.Shared/Prism.DryIoc.Shared.shproj b/src/Containers/Prism.DryIoc.Shared/Prism.DryIoc.Shared.shproj deleted file mode 100644 index ba802d8932..0000000000 --- a/src/Containers/Prism.DryIoc.Shared/Prism.DryIoc.Shared.shproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - 6e7ec81d-da39-4c4f-a898-0148558c34f4 - 14.0 - - - - - - - - diff --git a/src/Containers/Prism.DryIoc.Shared/PrismIocExtensions.cs b/src/Containers/Prism.DryIoc.Shared/PrismIocExtensions.cs deleted file mode 100644 index 94f809e065..0000000000 --- a/src/Containers/Prism.DryIoc.Shared/PrismIocExtensions.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Prism.Ioc; -using IContainer = DryIoc.IContainer; - -namespace Prism.DryIoc -{ - /// - /// Extensions help get the underlying - /// - public static class PrismIocExtensions - { - /// - /// Gets the from the - /// - /// The current - /// The underlying - public static IContainer GetContainer(this IContainerProvider containerProvider) - { - return ((IContainerExtension)containerProvider).Instance; - } - - /// - /// Gets the from the - /// - /// The current - /// The underlying - public static IContainer GetContainer(this IContainerRegistry containerRegistry) - { - return ((IContainerExtension)containerRegistry).Instance; - } - } -} diff --git a/src/Containers/Prism.Unity.Shared/Prism.Unity.Shared.projitems b/src/Containers/Prism.Unity.Shared/Prism.Unity.Shared.projitems deleted file mode 100644 index 06152c646d..0000000000 --- a/src/Containers/Prism.Unity.Shared/Prism.Unity.Shared.projitems +++ /dev/null @@ -1,15 +0,0 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - true - d66336a6-07e5-401a-a710-daedd6975d59 - - - Prism.Unity - - - - - - \ No newline at end of file diff --git a/src/Containers/Prism.Unity.Shared/Prism.Unity.Shared.shproj b/src/Containers/Prism.Unity.Shared/Prism.Unity.Shared.shproj deleted file mode 100644 index 8ce0b4e3e1..0000000000 --- a/src/Containers/Prism.Unity.Shared/Prism.Unity.Shared.shproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - d66336a6-07e5-401a-a710-daedd6975d59 - 14.0 - - - - - - - - diff --git a/src/Containers/Prism.Unity.Shared/PrismIocExtensions.cs b/src/Containers/Prism.Unity.Shared/PrismIocExtensions.cs deleted file mode 100644 index 33e60a4ad9..0000000000 --- a/src/Containers/Prism.Unity.Shared/PrismIocExtensions.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Prism.Ioc; -using Unity; - -namespace Prism.Unity -{ - /// - /// Extensions help get the underlying - /// - public static class PrismIocExtensions - { - /// - /// Gets the from the - /// - /// The current - /// The underlying - public static IUnityContainer GetContainer(this IContainerProvider containerProvider) - { - return ((IContainerExtension)containerProvider).Instance; - } - - /// - /// Gets the from the - /// - /// The current - /// The underlying - public static IUnityContainer GetContainer(this IContainerRegistry containerRegistry) - { - return ((IContainerExtension)containerRegistry).Instance; - } - } -} diff --git a/src/Containers/Prism.Unity.Shared/UnityContainerExtension.cs b/src/Containers/Prism.Unity.Shared/UnityContainerExtension.cs deleted file mode 100644 index bf4cfc4fff..0000000000 --- a/src/Containers/Prism.Unity.Shared/UnityContainerExtension.cs +++ /dev/null @@ -1,449 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Prism.Ioc; -using Prism.Ioc.Internals; -using Unity; -using Unity.Lifetime; -using Unity.Resolution; - -namespace Prism.Unity -{ - /// - /// The Unity implementation of the - /// -#if ContainerExtensions - internal partial -#else - public -#endif - class UnityContainerExtension : IContainerExtension, IContainerInfo - { - private UnityScopedProvider _currentScope; - - /// - /// The instance of the wrapped container - /// - public IUnityContainer Instance { get; } - -#if !ContainerExtensions - /// - /// Constructs a default - /// - public UnityContainerExtension() - : this(new UnityContainer()) - { - } - - /// - /// Constructs a with the specified - /// - /// - public UnityContainerExtension(IUnityContainer container) - { - Instance = container; - string currentContainer = "CurrentContainer"; - Instance.RegisterInstance(currentContainer, this); - Instance.RegisterFactory(typeof(IContainerExtension), c => c.Resolve(currentContainer)); - Instance.RegisterFactory(typeof(IContainerProvider), c => c.Resolve(currentContainer)); - ExceptionExtensions.RegisterFrameworkExceptionType(typeof(ResolutionFailedException)); - } -#endif - - /// - /// Gets the current - /// - public IScopedProvider CurrentScope => _currentScope; - - /// - /// Used to perform any final steps for configuring the extension that may be required by the container. - /// - public void FinalizeExtension() { } - - /// - /// Registers an instance of a given - /// - /// The service that is being registered - /// The instance of the service or - /// The instance - public IContainerRegistry RegisterInstance(Type type, object instance) - { - Instance.RegisterInstance(type, instance); - return this; - } - - /// - /// Registers an instance of a given with the specified name or key - /// - /// The service that is being registered - /// The instance of the service or - /// The name or key to register the service - /// The instance - public IContainerRegistry RegisterInstance(Type type, object instance, string name) - { - Instance.RegisterInstance(type, name, instance); - return this; - } - - /// - /// Registers a Singleton with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The instance - public IContainerRegistry RegisterSingleton(Type from, Type to) - { - Instance.RegisterSingleton(from, to); - return this; - } - - /// - /// Registers a Singleton with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The name or key to register the service - /// The instance - public IContainerRegistry RegisterSingleton(Type from, Type to, string name) - { - Instance.RegisterSingleton(from, to, name); - return this; - } - - /// - /// Registers a Singleton with the given service factory delegate method. - /// - /// The service - /// The delegate method. - /// The instance - public IContainerRegistry RegisterSingleton(Type type, Func factoryMethod) - { - Instance.RegisterFactory(type, _ => factoryMethod(), new ContainerControlledLifetimeManager()); - return this; - } - - /// - /// Registers a Singleton with the given service factory delegate method. - /// - /// The service - /// The delegate method using . - /// The instance - public IContainerRegistry RegisterSingleton(Type type, Func factoryMethod) - { - Instance.RegisterFactory(type, c => factoryMethod(c.Resolve()), new ContainerControlledLifetimeManager()); - return this; - } - - /// - /// Registers a Singleton Service which implements service interfaces - /// - /// The implementation . - /// The service 's. - /// The instance - /// Registers all interfaces if none are specified. - public IContainerRegistry RegisterManySingleton(Type type, params Type[] serviceTypes) - { - Instance.RegisterSingleton(type); - return RegisterManyInternal(type, serviceTypes); - } - - private IContainerRegistry RegisterManyInternal(Type implementingType, Type[] serviceTypes) - { - if (serviceTypes is null || serviceTypes.Length == 0) - { - serviceTypes = implementingType.GetInterfaces().Where(x => x != typeof(IDisposable)).ToArray(); - } - - foreach (var service in serviceTypes) - { - Instance.RegisterFactory(service, c => c.Resolve(implementingType)); - } - - return this; - } - - /// - /// Registers a Transient with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The instance - public IContainerRegistry Register(Type from, Type to) - { - Instance.RegisterType(from, to); - return this; - } - - /// - /// Registers a Transient with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The name or key to register the service - /// The instance - public IContainerRegistry Register(Type from, Type to, string name) - { - Instance.RegisterType(from, to, name); - return this; - } - - /// - /// Registers a Transient Service using a delegate method - /// - /// The service - /// The delegate method. - /// The instance - public IContainerRegistry Register(Type type, Func factoryMethod) - { - Instance.RegisterFactory(type, _ => factoryMethod()); - return this; - } - - /// - /// Registers a Transient Service using a delegate method - /// - /// The service - /// The delegate method using . - /// The instance - public IContainerRegistry Register(Type type, Func factoryMethod) - { - Instance.RegisterFactory(type, c => factoryMethod(c.Resolve())); - return this; - } - - /// - /// Registers a Transient Service which implements service interfaces - /// - /// The implementing . - /// The service 's. - /// The instance - /// Registers all interfaces if none are specified. - public IContainerRegistry RegisterMany(Type type, params Type[] serviceTypes) - { - Instance.RegisterType(type); - return RegisterManyInternal(type, serviceTypes); - } - - /// - /// Registers a scoped service - /// - /// The service - /// The implementation - /// The instance - public IContainerRegistry RegisterScoped(Type from, Type to) - { - Instance.RegisterType(from, to, new HierarchicalLifetimeManager()); - return this; - } - - /// - /// Registers a scoped service using a delegate method. - /// - /// The service - /// The delegate method. - /// The instance - public IContainerRegistry RegisterScoped(Type type, Func factoryMethod) - { - Instance.RegisterFactory(type, c => factoryMethod(), new HierarchicalLifetimeManager()); - return this; - } - - /// - /// Registers a scoped service using a delegate method. - /// - /// The service . - /// The delegate method. - /// The instance - public IContainerRegistry RegisterScoped(Type type, Func factoryMethod) - { - Instance.RegisterFactory(type, c => factoryMethod(c.Resolve()), new HierarchicalLifetimeManager()); - return this; - } - - /// - /// Resolves a given - /// - /// The service - /// The resolved Service - public object Resolve(Type type) => - Resolve(type, Array.Empty<(Type, object)>()); - - /// - /// Resolves a given - /// - /// The service - /// The service name/key used when registering the - /// The resolved Service - public object Resolve(Type type, string name) => - Resolve(type, name, Array.Empty<(Type, object)>()); - - /// - /// Resolves a given - /// - /// The service - /// Typed parameters to use when resolving the Service - /// The resolved Service - public object Resolve(Type type, params (Type Type, object Instance)[] parameters) - { - try - { - var c = _currentScope?.Container ?? Instance; - var overrides = parameters.Select(p => new DependencyOverride(p.Type, p.Instance)).ToArray(); - - if (typeof(IEnumerable).IsAssignableFrom(type) && type.GetGenericArguments().Length > 0) - { - type = type.GetGenericArguments()[0]; - return c.ResolveAll(type, overrides); - } - - return c.Resolve(type, overrides); - } - catch (Exception ex) - { - throw new ContainerResolutionException(type, ex, this); - } - } - - /// - /// Resolves a given - /// - /// The service - /// The service name/key used when registering the - /// Typed parameters to use when resolving the Service - /// The resolved Service - public object Resolve(Type type, string name, params (Type Type, object Instance)[] parameters) - { - try - { - var c = _currentScope?.Container ?? Instance; - - // Unity will simply return a new object() for unregistered Views - if (!c.IsRegistered(type, name)) - throw new KeyNotFoundException($"No registered type {type.Name} with the key {name}."); - - var overrides = parameters.Select(p => new DependencyOverride(p.Type, p.Instance)).ToArray(); - return c.Resolve(type, name, overrides); - } - catch (Exception ex) - { - throw new ContainerResolutionException(type, name, ex, this); - } - } - - /// - /// Determines if a given service is registered - /// - /// The service - /// true if the service is registered. - public bool IsRegistered(Type type) - { - return Instance.IsRegistered(type); - } - - /// - /// Determines if a given service is registered with the specified name - /// - /// The service - /// The service name or key used - /// true if the service is registered. - public bool IsRegistered(Type type, string name) - { - return Instance.IsRegistered(type, name); - } - - Type IContainerInfo.GetRegistrationType(string key) - { - //First try friendly name registration. If not found, try type registration - var matchingRegistration = Instance.Registrations.Where(r => key.Equals(r.Name, StringComparison.Ordinal)).FirstOrDefault(); - if (matchingRegistration == null) - { - matchingRegistration = Instance.Registrations.Where(r => key.Equals(r.RegisteredType.Name, StringComparison.Ordinal)).FirstOrDefault(); - } - - return matchingRegistration?.MappedToType; - } - - Type IContainerInfo.GetRegistrationType(Type serviceType) - { - var matchingRegistration = Instance.Registrations.Where(x => x.RegisteredType == serviceType).FirstOrDefault(); - return matchingRegistration?.MappedToType; - } - - /// - /// Creates a new Scope - /// - public virtual IScopedProvider CreateScope() => - CreateScopeInternal(); - - /// - /// Creates a new Scope and provides the updated ServiceProvider - /// - /// A child . - /// - /// This should be called by custom implementations that Implement IServiceScopeFactory - /// - protected IScopedProvider CreateScopeInternal() - { - var child = Instance.CreateChildContainer(); - _currentScope = new UnityScopedProvider(child); - return _currentScope; - } - - private class UnityScopedProvider : IScopedProvider - { - public UnityScopedProvider(IUnityContainer container) - { - Container = container; - } - - public IUnityContainer Container { get; private set; } - public bool IsAttached { get; set; } - public IScopedProvider CurrentScope => this; - - public IScopedProvider CreateScope() => this; - - public void Dispose() - { - Container.Dispose(); - Container = null; - } - - public object Resolve(Type type) => - Resolve(type, Array.Empty<(Type, object)>()); - - public object Resolve(Type type, string name) => - Resolve(type, name, Array.Empty<(Type, object)>()); - - public object Resolve(Type type, params (Type Type, object Instance)[] parameters) - { - try - { - var overrides = parameters.Select(p => new DependencyOverride(p.Type, p.Instance)).ToArray(); - return Container.Resolve(type, overrides); - } - catch (Exception ex) - { - throw new ContainerResolutionException(type, ex, this); - } - } - - public object Resolve(Type type, string name, params (Type Type, object Instance)[] parameters) - { - try - { - // Unity will simply return a new object() for unregistered Views - if (!Container.IsRegistered(type, name)) - throw new KeyNotFoundException($"No registered type {type.Name} with the key {name}."); - - var overrides = parameters.Select(p => new DependencyOverride(p.Type, p.Instance)).ToArray(); - return Container.Resolve(type, name, overrides); - } - catch (Exception ex) - { - throw new ContainerResolutionException(type, name, ex, this); - } - } - } - } -} diff --git a/src/Forms/Prism.DryIoc.Forms/Prism.DryIoc.Forms.csproj b/src/Forms/Prism.DryIoc.Forms/Prism.DryIoc.Forms.csproj index 83bd4f3b3f..329e0ec8ef 100644 --- a/src/Forms/Prism.DryIoc.Forms/Prism.DryIoc.Forms.csproj +++ b/src/Forms/Prism.DryIoc.Forms/Prism.DryIoc.Forms.csproj @@ -11,13 +11,11 @@ - + - - diff --git a/src/Forms/Prism.DryIoc.Forms/PrismApplication.cs b/src/Forms/Prism.DryIoc.Forms/PrismApplication.cs index d05ba65958..9e2e9fdc89 100644 --- a/src/Forms/Prism.DryIoc.Forms/PrismApplication.cs +++ b/src/Forms/Prism.DryIoc.Forms/PrismApplication.cs @@ -1,4 +1,5 @@ using DryIoc; +using Prism.Container.DryIoc; using Prism.Ioc; using Xamarin.Forms.Internals; @@ -40,7 +41,7 @@ protected PrismApplication(IPlatformInitializer platformInitializer, bool setFor /// protected override IContainerExtension CreateContainerExtension() { - return new DryIocContainerExtension(new Container(CreateContainerRules())); + return new DryIocContainerExtension(CreateContainerRules()); } /// diff --git a/src/Forms/Prism.Forms/Navigation/PageNavigationService.cs b/src/Forms/Prism.Forms/Navigation/PageNavigationService.cs index 382090704d..ea20dea231 100644 --- a/src/Forms/Prism.Forms/Navigation/PageNavigationService.cs +++ b/src/Forms/Prism.Forms/Navigation/PageNavigationService.cs @@ -843,7 +843,7 @@ protected virtual Page CreatePage(string segmentName) } catch (Exception ex) { - if (((IContainerRegistry)_container).IsRegistered(segmentName)) + if (_container.IsRegistered(segmentName)) throw new NavigationException(NavigationException.ErrorCreatingPage, _page, ex); throw new NavigationException(NavigationException.NoPageIsRegistered, _page, ex); diff --git a/src/Forms/Prism.Forms/PrismApplicationBase.cs b/src/Forms/Prism.Forms/PrismApplicationBase.cs index 3a8d2881af..3af9466821 100644 --- a/src/Forms/Prism.Forms/PrismApplicationBase.cs +++ b/src/Forms/Prism.Forms/PrismApplicationBase.cs @@ -140,15 +140,21 @@ private INavigationService CreateNavigationService(object view) /// protected virtual void Initialize() { - ContainerLocator.SetContainerExtension(CreateContainerExtension); + var initialize = ContainerLocator.TrySetContainerExtension(CreateContainerExtension()); _containerExtension = ContainerLocator.Current; - RegisterRequiredTypes(_containerExtension); - PlatformInitializer?.RegisterTypes(_containerExtension); - RegisterTypes(_containerExtension); - _containerExtension.FinalizeExtension(); + if (initialize) + { + RegisterRequiredTypes(_containerExtension); + PlatformInitializer?.RegisterTypes(_containerExtension); + RegisterTypes(_containerExtension); + + _containerExtension.FinalizeExtension(); + + _moduleCatalog = Container.Resolve(); + ConfigureModuleCatalog(_moduleCatalog); + } - _moduleCatalog = Container.Resolve(); - ConfigureModuleCatalog(_moduleCatalog); + _moduleCatalog ??= Container.Resolve(); _containerExtension.CreateScope(); NavigationService = _containerExtension.Resolve(); diff --git a/src/Forms/Prism.Unity.Forms/Prism.Unity.Forms.csproj b/src/Forms/Prism.Unity.Forms/Prism.Unity.Forms.csproj index 353e7ab0c3..d29862b2e2 100644 --- a/src/Forms/Prism.Unity.Forms/Prism.Unity.Forms.csproj +++ b/src/Forms/Prism.Unity.Forms/Prism.Unity.Forms.csproj @@ -11,13 +11,11 @@ - + - - diff --git a/src/Forms/Prism.Unity.Forms/PrismApplication.cs b/src/Forms/Prism.Unity.Forms/PrismApplication.cs index f15c57c7ca..d13880ad1a 100644 --- a/src/Forms/Prism.Unity.Forms/PrismApplication.cs +++ b/src/Forms/Prism.Unity.Forms/PrismApplication.cs @@ -1,4 +1,5 @@ -using Prism.Ioc; +using Prism.Container.Unity; +using Prism.Ioc; using Unity; [assembly: Xamarin.Forms.XmlnsDefinition("http://prismlibrary.com", "Prism.Unity")] diff --git a/src/Maui/Prism.DryIoc.Maui/DryIocContainerExtension.cs b/src/Maui/Prism.DryIoc.Maui/DryIocContainerExtension.cs deleted file mode 100644 index b0dbe4c33a..0000000000 --- a/src/Maui/Prism.DryIoc.Maui/DryIocContainerExtension.cs +++ /dev/null @@ -1,55 +0,0 @@ -using DryIoc; -using Prism.Ioc; -using IContainer = DryIoc.IContainer; - -namespace Prism.DryIoc; - -partial class DryIocContainerExtension : IServiceCollectionAware -{ - public IServiceProvider CreateServiceProvider() - { - var capabilities = new DryIocServiceProviderCapabilities(Instance); - var singletons = Instance.SingletonScope; - singletons.Use(capabilities); - singletons.Use(capabilities); - singletons.UseFactory(r => new DryIocServiceScopeFactory(r)); - - return Instance; - } - - public void Populate(IServiceCollection services) - { - foreach (var descriptor in services) - RegisterDescriptor(Instance, descriptor); - - var errors = Instance.Validate(); - } - - static IReuse ToReuse(ServiceLifetime lifetime) => - lifetime == ServiceLifetime.Singleton ? Reuse.Singleton : - lifetime == ServiceLifetime.Scoped ? Reuse.ScopedOrSingleton : // see, that we have Reuse.ScopedOrSingleton here instead of Reuse.Scoped - Reuse.Transient; - - static void RegisterDescriptor(IContainer container, ServiceDescriptor descriptor) - { - var serviceType = descriptor.ServiceType; - var implType = descriptor.ImplementationType; - if (implType != null) - { - container.Register(ReflectionFactory.Of(implType, ToReuse(descriptor.Lifetime)), serviceType, - null, null, isStaticallyChecked: implType == serviceType); - } - else if (descriptor.ImplementationFactory != null) - { - container.Register(DelegateFactory.Of(descriptor.ImplementationFactory.ToFactoryDelegate, ToReuse(descriptor.Lifetime)), serviceType, - null, null, isStaticallyChecked: true); - } - else - { - var instance = descriptor.ImplementationInstance; - container.Register(InstanceFactory.Of(instance), serviceType, - null, null, isStaticallyChecked: true); - container.TrackDisposable(instance); - } - } -} diff --git a/src/Maui/Prism.DryIoc.Maui/DryIocServiceProviderCapabilities.cs b/src/Maui/Prism.DryIoc.Maui/DryIocServiceProviderCapabilities.cs deleted file mode 100644 index 5919f6e1a4..0000000000 --- a/src/Maui/Prism.DryIoc.Maui/DryIocServiceProviderCapabilities.cs +++ /dev/null @@ -1,39 +0,0 @@ -using DryIoc; -using Prism.Ioc; -using IContainer = DryIoc.IContainer; - -namespace Prism.DryIoc; - -internal sealed class DryIocServiceProviderCapabilities : IServiceProviderIsService, ISupportRequiredService -{ - private readonly IContainer _container; - /// Statefully wraps the passed - public DryIocServiceProviderCapabilities(IContainer container) => _container = container; - - /// - public bool IsService(Type serviceType) - { - // I am not fully comprehend but MS.DI considers asking for the open-generic type even if it is registered to return `false` - // Probably mixing here the fact that open type cannot be instantiated without providing the concrete type argument. - // But I think it is conflating two things and making the reasoning harder. - if (serviceType.IsGenericTypeDefinition) - return false; - - if (serviceType == typeof(IServiceProviderIsService) || - serviceType == typeof(ISupportRequiredService) || - serviceType == typeof(IServiceScopeFactory)) - return true; - - if (_container.IsRegistered(serviceType)) - return true; - - if (serviceType.IsGenericType && - _container.IsRegistered(serviceType.GetGenericTypeDefinition())) - return true; - - return _container.IsRegistered(serviceType, factoryType: FactoryType.Wrapper); - } - - /// - public object GetRequiredService(Type serviceType) => _container.Resolve(serviceType); -} diff --git a/src/Maui/Prism.DryIoc.Maui/DryIocServiceScope.cs b/src/Maui/Prism.DryIoc.Maui/DryIocServiceScope.cs deleted file mode 100644 index 075aadb1a4..0000000000 --- a/src/Maui/Prism.DryIoc.Maui/DryIocServiceScope.cs +++ /dev/null @@ -1,16 +0,0 @@ -using DryIoc; - -namespace Prism.DryIoc; - -internal sealed class DryIocServiceScope : IServiceScope -{ - /// - public IServiceProvider ServiceProvider => _resolverContext; - private readonly IResolverContext _resolverContext; - - /// Creating from resolver context - public DryIocServiceScope(IResolverContext resolverContext) => _resolverContext = resolverContext; - - /// Disposes the underlying resolver context - public void Dispose() => _resolverContext.Dispose(); -} diff --git a/src/Maui/Prism.DryIoc.Maui/DryIocServiceScopeFactory.cs b/src/Maui/Prism.DryIoc.Maui/DryIocServiceScopeFactory.cs deleted file mode 100644 index 1c67610773..0000000000 --- a/src/Maui/Prism.DryIoc.Maui/DryIocServiceScopeFactory.cs +++ /dev/null @@ -1,23 +0,0 @@ -using DryIoc; - -namespace Prism.DryIoc; - -internal sealed class DryIocServiceScopeFactory : IServiceScopeFactory -{ - private readonly IResolverContext _scopedResolver; - - /// Stores passed scoped container to open nested scope. - /// Scoped container to be used to create nested scope. - public DryIocServiceScopeFactory(IResolverContext scopedResolver) => _scopedResolver = scopedResolver; - - /// Opens scope and wraps it into DI interface. - /// DI wrapper of opened scope. - public IServiceScope CreateScope() - { - var r = _scopedResolver; - var scope = r.ScopeContext == null - ? Scope.Of(r.OwnCurrentScope) - : r.ScopeContext.SetCurrent(p => Scope.Of(p)); - return new DryIocServiceScope(r.WithCurrentScope(scope)); - } -} diff --git a/src/Maui/Prism.DryIoc.Maui/Prism.DryIoc.Maui.csproj b/src/Maui/Prism.DryIoc.Maui/Prism.DryIoc.Maui.csproj index c57e3b3fde..d52263e4b3 100644 --- a/src/Maui/Prism.DryIoc.Maui/Prism.DryIoc.Maui.csproj +++ b/src/Maui/Prism.DryIoc.Maui/Prism.DryIoc.Maui.csproj @@ -9,7 +9,7 @@ - + @@ -18,6 +18,4 @@ - - diff --git a/src/Maui/Prism.DryIoc.Maui/PrismAppExtensions.cs b/src/Maui/Prism.DryIoc.Maui/PrismAppExtensions.cs index 37754f8285..a43dda8558 100644 --- a/src/Maui/Prism.DryIoc.Maui/PrismAppExtensions.cs +++ b/src/Maui/Prism.DryIoc.Maui/PrismAppExtensions.cs @@ -1,6 +1,5 @@ using DryIoc; using Prism; -using Prism.DryIoc; namespace Microsoft.Maui; diff --git a/src/Maui/Prism.Maui/Ioc/BehaviorFactoryRegistrationExtensions.cs b/src/Maui/Prism.Maui/Ioc/BehaviorFactoryRegistrationExtensions.cs index 7a947be2e2..4827e91821 100644 --- a/src/Maui/Prism.Maui/Ioc/BehaviorFactoryRegistrationExtensions.cs +++ b/src/Maui/Prism.Maui/Ioc/BehaviorFactoryRegistrationExtensions.cs @@ -2,6 +2,9 @@ namespace Prism.Ioc; +/// +/// Provides extensions for registering Behaviors to add to pages. +/// public static class BehaviorFactoryRegistrationExtensions { /// @@ -52,18 +55,45 @@ public static IContainerRegistry RegisterPageBehavior(this ICo p.Behaviors.Add(c.Resolve()); }); + /// + /// Registers an delegate to execute on a given Page instance. This could apply a + /// or it could add attached properties such Platform Specifics. + /// + /// The . + /// The delegate action to perform on the . + /// The . public static IServiceCollection RegisterPageBehaviorFactory(this IServiceCollection services, Action pageBehaviorFactory) => services.AddSingleton(new DelegatePageBehaviorFactory(pageBehaviorFactory)); + /// + /// Registers an delegate to execute on a given Page instance. This could apply a + /// or it could add attached properties such Platform Specifics. + /// + /// The . + /// The delegate action to perform on the . + /// The . public static IServiceCollection RegisterPageBehaviorFactory(this IServiceCollection services, Action pageBehaviorFactory) => services.AddScoped(c => new DelegateContainerPageBehaviorFactory(pageBehaviorFactory, c.GetRequiredService())); + /// + /// Registers a given for all Pages. + /// + /// The type. + /// The . + /// The . public static IServiceCollection RegisterPageBehavior(this IServiceCollection services) where TBehavior : Behavior => services .AddTransient() .RegisterPageBehaviorFactory((c, p) => p.Behaviors.Add(c.Resolve())); + /// + /// Registers a given for the specified type of + /// + /// The type. + /// The type. + /// The . + /// The . public static IServiceCollection RegisterPageBehavior(this IServiceCollection services) where TPage : Page where TBehavior : Behavior => diff --git a/src/Maui/Prism.Maui/Ioc/IServiceCollectionAware.cs b/src/Maui/Prism.Maui/Ioc/IServiceCollectionAware.cs deleted file mode 100644 index 2d6ccfc895..0000000000 --- a/src/Maui/Prism.Maui/Ioc/IServiceCollectionAware.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Prism.Ioc; - -public interface IServiceCollectionAware -{ - void Populate(IServiceCollection services); - IServiceProvider CreateServiceProvider(); -} diff --git a/src/Maui/Prism.Maui/Ioc/MicrosoftDependencyInjectionExtensions.cs b/src/Maui/Prism.Maui/Ioc/MicrosoftDependencyInjectionExtensions.cs index ddacf64132..b714514cdf 100644 --- a/src/Maui/Prism.Maui/Ioc/MicrosoftDependencyInjectionExtensions.cs +++ b/src/Maui/Prism.Maui/Ioc/MicrosoftDependencyInjectionExtensions.cs @@ -2,24 +2,14 @@ namespace Prism.Ioc; +/// +/// Navigation Extensions for working with the +/// public static class MicrosoftDependencyInjectionExtensions { - public static void Populate(this IContainerExtension container, IServiceCollection services) - { - if (container is not IServiceCollectionAware sca) - throw new InvalidOperationException("The instance of IContainerExtension does not implement IServiceCollectionAware"); - - sca.Populate(services); - } - - public static IServiceProvider CreateServiceProvider(this IContainerExtension container) - { - if (container is not IServiceCollectionAware sca) - throw new InvalidOperationException("The instance of IContainerExtension does not implement IServiceCollectionAware"); - - return sca.CreateServiceProvider(); - } #if !UNO_WINUI_PROJECT + private static readonly Type PageType = typeof(Page); + public static IServiceCollection RegisterForNavigation(this IServiceCollection services, string name = null) where TView : Page => services.RegisterForNavigation(typeof(TView), null, name); @@ -33,6 +23,9 @@ public static IServiceCollection RegisterForNavigation(this IServiceCollection s if (view is null) throw new ArgumentNullException(nameof(view)); + if (!view.IsAssignableTo(PageType)) + throw new InvalidOperationException($"The view type '{view.FullName}' is not a type of Page."); + if (string.IsNullOrEmpty(name)) name = view.Name; diff --git a/src/Maui/Prism.Maui/Ioc/PrismServiceProviderFactory.cs b/src/Maui/Prism.Maui/Ioc/PrismServiceProviderFactory.cs deleted file mode 100644 index a8af18c28e..0000000000 --- a/src/Maui/Prism.Maui/Ioc/PrismServiceProviderFactory.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace Prism.Ioc; - -public class PrismServiceProviderFactory : IServiceProviderFactory -{ - private Action _registerTypes { get; } - - public PrismServiceProviderFactory(Action registerTypes) - { - _registerTypes = registerTypes; - } - - public IContainerExtension CreateBuilder(IServiceCollection services) - { - var container = ContainerLocator.Current; - container.Populate(services); - _registerTypes(container); - - return container; - } - - public IServiceProvider CreateServiceProvider(IContainerExtension containerExtension) - { - return containerExtension.CreateServiceProvider(); - } -} diff --git a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs index 87c0f29f03..f7d0b49e40 100644 --- a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs +++ b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs @@ -2,7 +2,6 @@ using System.Web; using Prism.Common; using Prism.Events; -using Prism.Ioc; using Prism.Mvvm; using Application = Microsoft.Maui.Controls.Application; using XamlTab = Prism.Navigation.Xaml.TabbedPage; diff --git a/src/Maui/Prism.Maui/PrismAppBuilder.cs b/src/Maui/Prism.Maui/PrismAppBuilder.cs index 6dcaa4bb5b..7a2143e6d8 100644 --- a/src/Maui/Prism.Maui/PrismAppBuilder.cs +++ b/src/Maui/Prism.Maui/PrismAppBuilder.cs @@ -5,7 +5,6 @@ using Prism.Controls; using Prism.Dialogs; using Prism.Events; -using Prism.Ioc; using Prism.Modularity; using Prism.Mvvm; using Prism.Navigation; @@ -77,7 +76,7 @@ internal PrismAppBuilder(IContainerExtension containerExtension, MauiAppBuilder }); ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => containerExtension); + ContainerLocator.SetContainerExtension(containerExtension); containerExtension.RegisterInstance(this); containerExtension.RegisterSingleton(); @@ -85,6 +84,9 @@ internal PrismAppBuilder(IContainerExtension containerExtension, MauiAppBuilder ConfigureViewModelLocator(); } + /// + /// Gets the associated . + /// public MauiAppBuilder MauiBuilder { get; } private void ConfigureViewModelLocator() @@ -117,12 +119,22 @@ internal static object DefaultViewModelLocator(object view, Type viewModelType) } } + /// + /// Provides a Delegate to register services with the + /// + /// The delegate to register your services. + /// The . public PrismAppBuilder RegisterTypes(Action registerTypes) { _registrations.Add(registerTypes); return this; } + /// + /// Provides a Delegate to invoke when the App is initialized. + /// + /// The delegate to invoke. + /// The . public PrismAppBuilder OnInitialized(Action action) { _initializations.Add(action); @@ -176,6 +188,12 @@ internal void OnAppStarted() onStart.Wait(); } + /// + /// When the is started and the native platform calls + /// this delegate will be invoked to do your initial Navigation. + /// + /// The Navigation Delegate. + /// The . public PrismAppBuilder OnAppStart(Func onAppStarted) { _onAppStarted = onAppStarted; @@ -206,12 +224,22 @@ private void RegistrationCallback(IContainerExtension container) _registrations.ForEach(action => action(container)); } + /// + /// Configures for Region Navigation with the . + /// + /// Delegate to configure the . + /// The . public PrismAppBuilder ConfigureRegionAdapters(Action configureMappings) { _configureAdapters = configureMappings; return this; } + /// + /// Configures the . + /// + /// Delegate to configure the . + /// The . public PrismAppBuilder ConfigureRegionBehaviors(Action configureBehaviors) { _configureBehaviors = configureBehaviors; diff --git a/src/Prism.Core/Extensions/ExceptionExtensions.cs b/src/Prism.Core/Extensions/ExceptionExtensions.cs deleted file mode 100644 index daa655bd2b..0000000000 --- a/src/Prism.Core/Extensions/ExceptionExtensions.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System.Collections.Generic; - -namespace System -{ - /// - /// Class that provides extension methods for the Exception class. These extension methods provide - /// a mechanism for developers to get more easily to the root cause of an exception, especially in combination with - /// DI-containers such as Unity. - /// - public static class ExceptionExtensions - { - private static List frameworkExceptionTypes = new List(); - - /// - /// Register the type of an Exception that is thrown by the framework. The method uses - /// this list of Exception types to find out if something has gone wrong. - /// - /// The type of exception to register. - public static void RegisterFrameworkExceptionType(Type frameworkExceptionType) - { - if (frameworkExceptionType == null) throw new ArgumentNullException(nameof(frameworkExceptionType)); - - if (!frameworkExceptionTypes.Contains(frameworkExceptionType)) - frameworkExceptionTypes.Add(frameworkExceptionType); - } - - - /// - /// Determines whether the exception type is already registered using the - /// method - /// - /// The type of framework exception to find. - /// - /// true if the exception type is already registered; otherwise, false. - /// - public static bool IsFrameworkExceptionRegistered(Type frameworkExceptionType) - { - return frameworkExceptionTypes.Contains(frameworkExceptionType); - } - - /// - /// Looks at all the inner exceptions of the parameter to find the - /// most likely root cause of the exception. This works by skipping all registered exception types. - /// - /// - /// This method is not 100% accurate and should only be used to point a developer into the most likely direction. - /// It should not be used to replace the Inner Exception stack of an exception, because this might hide required exception - /// information. - /// - /// The exception that will provide the list of inner exceptions to examine. - /// - /// The exception that most likely caused the exception to occur. If it can't find the root exception, it will return the - /// value itself. - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "We have to catch exception. This method is used in exception handling code, so it must not fail.")] - public static Exception GetRootException(this Exception exception) - { - Exception rootException = exception; - - try - { - while (true) - { - if (rootException == null) - { - rootException = exception; - break; - } - - if (!IsFrameworkException(rootException)) - { - break; - } - rootException = rootException.InnerException; - } - } - catch (Exception) - { - rootException = exception; - } - return rootException; - } - - private static bool IsFrameworkException(Exception exception) - { - bool isFrameworkException = frameworkExceptionTypes.Contains(exception.GetType()); - bool childIsFrameworkException = false; - - if (exception.InnerException != null) - { - childIsFrameworkException = frameworkExceptionTypes.Contains(exception.InnerException.GetType()); - } - - return isFrameworkException || childIsFrameworkException; - } - } -} diff --git a/src/Prism.Core/Ioc/ContainerLocator.cs b/src/Prism.Core/Ioc/ContainerLocator.cs deleted file mode 100644 index 65b3f3a866..0000000000 --- a/src/Prism.Core/Ioc/ContainerLocator.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Prism.Ioc -{ - /// - /// The tracks the current instance of the Container used by your Application - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public static class ContainerLocator - { - private static Lazy _lazyContainer; - - private static IContainerExtension _current; - - /// - /// Gets the current . - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public static IContainerExtension Current => - _current ?? (_current = _lazyContainer?.Value); - - /// - /// Gets the - /// - public static IContainerProvider Container => - Current; - - /// - /// Sets the Container Factory to use if the Current is null - /// - /// - /// - /// NOTE: We want to use Lazy Initialization in case the container is first created - /// prior to Prism initializing which could be the case with Shiny - /// - public static void SetContainerExtension(Func factory) => - _lazyContainer = new Lazy(factory); - - /// - /// Used for Testing to Reset the Current Container - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public static void ResetContainer() - { - _current = null; - _lazyContainer = null; - } - } -} diff --git a/src/Prism.Core/Ioc/ContainerResolutionErrorCollection.cs b/src/Prism.Core/Ioc/ContainerResolutionErrorCollection.cs deleted file mode 100644 index c4148425cf..0000000000 --- a/src/Prism.Core/Ioc/ContainerResolutionErrorCollection.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Prism.Ioc -{ - /// - /// A collection of Errors encountered by while attempting to resolve a given type. - /// - public sealed class ContainerResolutionErrorCollection : IEnumerable> - { - private readonly List> _errors = new List>(); - - internal void Add(Type type, Exception exception) => - _errors.Add(new KeyValuePair(type, exception)); - - /// - /// Provides a list of 's affected. - /// - /// - /// This could include for Registered View's - /// - public IEnumerable Types => _errors.Select(x => x.Key).Distinct(); - - IEnumerator> IEnumerable>.GetEnumerator() => - _errors.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() => - _errors.GetEnumerator(); - } -} diff --git a/src/Prism.Core/Ioc/ContainerResolutionException.cs b/src/Prism.Core/Ioc/ContainerResolutionException.cs deleted file mode 100644 index 4f16d0289f..0000000000 --- a/src/Prism.Core/Ioc/ContainerResolutionException.cs +++ /dev/null @@ -1,261 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using System.Reflection; -using Prism.Ioc.Internals; - -namespace Prism.Ioc -{ - /// - /// Provides a common exception class to be used by when encountering a resolution exception - /// - [SuppressMessage("Design", "CA1032:Implement standard exception constructors", Justification = "The ContainerResolutionException is a specialized Exception to debug issues resolving services.")] - public class ContainerResolutionException : Exception - { - /// - /// The message provided by when no registration was found with the container - /// - public const string MissingRegistration = "No Registration was found in the container for the specified type"; - - /// - /// The message provided by when the implementing type is abstract - /// - public const string CannotResolveAbstractType = "The Implementing Type is abstract."; - - /// - /// The message provided by when multiple constructors were found in the implementing type - /// - public const string MultipleConstructors = "The Implementing Type has multiple constructors which may not be resolvable"; - - /// - /// The message provided by when no public constructors were found in the implementing type - /// - public const string NoPublicConstructors = "The Implementing Type has no public constructors which cause issues with the type being resolved."; - - /// - /// The message provided by when no public constructors were found in the implementing type - /// - public const string CyclicalDependency = "A cyclical dependency was detected. Type A requires an instance of Type A."; - - /// - /// The message provided by when we have no clue why the container failed. - /// - /// - /// Please file an issue with the Prism team if you encounter a ContainerResolutionException with this message - /// - public const string UnknownError = "You seem to have hit an edge case. Please file an issue with the Prism team along with a duplication."; - - private IContainerProvider _instance { get; } - /// - /// Creates a new instance of the - /// - /// The failed Service that was attempted to be resolved. - /// The actual thrown by the Container. - /// The instance of the container that was used to resolve the service type. - public ContainerResolutionException(Type serviceType, Exception innerException, IContainerProvider instance) - : this(serviceType, null, innerException, instance) - { - } - - /// - /// Creates a new instance of the - /// - /// The failed Service that was attempted to be resolved. - /// The Service Name/Key used to resolve the Service Type. - /// The actual thrown by the Container. - /// The instance of the container that was used to resolve the service type. - public ContainerResolutionException(Type serviceType, string serviceName, Exception innerException, IContainerProvider instance) - : base(GetErrorMessage(serviceType, serviceName), innerException) - { - _instance = instance; - ServiceType = serviceType; - ServiceName = serviceName; - } - - // Used by GetErrors() - private ContainerResolutionException(Type serviceType, string message, IContainerProvider instance) - : base(message) - { - _instance = instance; - ServiceType = serviceType; - } - - /// - /// Gets the ServiceType - /// - public Type ServiceType { get; } - - /// - /// Gets the Service Key if one was used to resolve the ServiceType - /// - /// - /// This is most commonly the key used to resolve a View for Navigation. - /// - public string ServiceName { get; } - - private bool IsKnownIssue - { - get - { - switch (Message) - { - // Be sure to add any constants here as new use cases emerge. - case MissingRegistration: - case CannotResolveAbstractType: - case MultipleConstructors: - case NoPublicConstructors: - case CyclicalDependency: - case UnknownError: - return true; - default: - return false; - } - } - } - - /// - /// Gets a Dictionary of errors and their corresponding types to help diagnose possible issues - /// that resulted in the ContainerResolutionException. - /// - /// A mapping types that encountered given exceptions in the resolution process. - public ContainerResolutionErrorCollection GetErrors() - { - var errors = new ContainerResolutionErrorCollection(); - if (IsKnownIssue) - { - return errors; - } - - var implementingType = TryFindImplementingType(); - if (implementingType is null) - { - errors.Add(ServiceType, new ContainerResolutionException(ServiceType, MissingRegistration, _instance)); - return errors; - } - else if (implementingType.IsAbstract) - { - errors.Add(ServiceType, new ContainerResolutionException(implementingType, CannotResolveAbstractType, _instance)); - } - - PopulateErrors(implementingType, ref errors); - return errors; - } - - private Type TryFindImplementingType() - { - var name = ServiceName; - - // A ViewModel generally isn't directly registered with the container - // as a result we want to provide the ServiceType when it's a concrete type. - var defaultValue = IsConcreteType(ServiceType) ? ServiceType : null; - if (string.IsNullOrEmpty(name)) - { - if (!_instance.IsRegistered(ServiceType)) - { - return defaultValue; - } - - // RegistrationType must be retrieved from the Root Container - return ContainerLocator.Current.GetRegistrationType(ServiceType); - } - else if (!_instance.IsRegistered(ServiceType, ServiceName)) - { - return defaultValue; - } - - // RegistrationType must be retrieved from the Root Container - return ContainerLocator.Current.GetRegistrationType(name); - } - - [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "This method is meant to collect any exception thrown.")] - private void PopulateErrors(Type implementingType, ref ContainerResolutionErrorCollection errors) - { - var ctors = implementingType.GetConstructors(); - - if (ctors.Length > 1) - { - errors.Add(implementingType, new ContainerResolutionException(implementingType, MultipleConstructors, _instance)); - } - else if (ctors.Length == 0) - { - errors.Add(implementingType, new ContainerResolutionException(implementingType, NoPublicConstructors, _instance)); - return; - } - - var ctor = ctors.OrderByDescending(x => x.GetParameters().Length).FirstOrDefault(); - var parameters = ctor.GetParameters(); - var parameterInstances = new List(); - foreach (var parameter in parameters) - { - try - { - var defaultImplementingType = IsConcreteType(parameter.ParameterType) ? parameter.ParameterType : null; - - // RegistrationType must be retrieved from the Root Container - var parameterImplementingType = ContainerLocator.Current.GetRegistrationType(parameter.ParameterType); - if (parameterImplementingType is null) - throw new ContainerResolutionException(parameter.ParameterType, MissingRegistration, _instance); - - var instance = _instance.Resolve(parameter.ParameterType); - parameterInstances.Add(instance); - } - catch (Exception ex) - { - // TODO: Add Exceptions Extensions lookup here to get root Exception - errors.Add(parameter.ParameterType, ex); - if (ex is ContainerResolutionException cre && !cre.IsKnownIssue) - { - foreach (var subError in cre.GetErrors()) - { - errors.Add(subError.Key, subError.Value); - } - } - } - } - - // Return if we had an error with any children - if (parameters.Length != parameterInstances.Count) - return; - - try - { - // We generally expect some sort of InvocationException Exception here... - ctor.Invoke(parameterInstances.ToArray()); - - // If we managed to create an instance for every parameter and the - // constructor didn't throw an exception when activating the instance - // we really aren't sure what allowed us to get here... - throw new ContainerResolutionException(implementingType, UnknownError, _instance); - } - catch (TargetInvocationException tie) - { - errors.Add(implementingType, tie); - - if (tie.InnerException != null) - errors.Add(implementingType, tie.InnerException); - } - catch (Exception ex) - { - errors.Add(implementingType, ex); - } - } - - private static bool IsConcreteType(Type type) - { - if (type.IsAbstract || type.IsEnum || type.IsPrimitive || type == typeof(object)) - return false; - - return true; - } - - private static string GetErrorMessage(Type type, string name) - { - var message = $"An unexpected error occurred while resolving '{type.FullName}'"; - if (!string.IsNullOrEmpty(name)) - message += $", with the service name '{name}'"; - - return message; - } - } -} diff --git a/src/Prism.Core/Ioc/IContainerExtension.cs b/src/Prism.Core/Ioc/IContainerExtension.cs deleted file mode 100644 index 48983b53bf..0000000000 --- a/src/Prism.Core/Ioc/IContainerExtension.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace Prism.Ioc -{ - /// - /// A strongly typed container extension - /// - /// The underlying root container - public interface IContainerExtension : IContainerExtension - { - /// - /// The instance of the wrapped container - /// - TContainer Instance { get; } - } - - /// - /// A generic abstraction for what Prism expects from a container - /// - public interface IContainerExtension : IContainerProvider, IContainerRegistry - { - /// - /// Used to perform any final steps for configuring the extension that may be required by the container. - /// - void FinalizeExtension(); - } -} diff --git a/src/Prism.Core/Ioc/IContainerProvider.cs b/src/Prism.Core/Ioc/IContainerProvider.cs deleted file mode 100644 index 5fbd036a9a..0000000000 --- a/src/Prism.Core/Ioc/IContainerProvider.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; - -namespace Prism.Ioc -{ - /// - /// Resolves Services from the Container - /// - public interface IContainerProvider - { - /// - /// Resolves a given - /// - /// The service - /// The resolved Service - object Resolve(Type type); - - /// - /// Resolves a given - /// - /// The service - /// Typed parameters to use when resolving the Service - /// The resolved Service - object Resolve(Type type, params (Type Type, object Instance)[] parameters); - - /// - /// Resolves a given - /// - /// The service - /// The service name/key used when registering the - /// The resolved Service - object Resolve(Type type, string name); - - /// - /// Resolves a given - /// - /// The service - /// The service name/key used when registering the - /// Typed parameters to use when resolving the Service - /// The resolved Service - object Resolve(Type type, string name, params (Type Type, object Instance)[] parameters); - - /// - /// Creates a new scope - /// - IScopedProvider CreateScope(); - - /// - /// Gets the Current Scope - /// - IScopedProvider CurrentScope { get; } - } -} diff --git a/src/Prism.Core/Ioc/IContainerProviderExtensions.cs b/src/Prism.Core/Ioc/IContainerProviderExtensions.cs deleted file mode 100644 index 5a53c79934..0000000000 --- a/src/Prism.Core/Ioc/IContainerProviderExtensions.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System; - -namespace Prism.Ioc -{ - /// - /// Provides Generic Type extensions for the - /// - public static class IContainerProviderExtensions - { - /// - /// Resolves a given - /// - /// The service - /// The current - /// The resolved Service - public static T Resolve(this IContainerProvider provider) - { - return (T)provider.Resolve(typeof(T)); - } - - /// - /// Resolves a given - /// - /// The service - /// The current - /// Typed parameters to use when resolving the Service - /// The resolved Service - public static T Resolve(this IContainerProvider provider, params (Type Type, object Instance)[] parameters) - { - return (T)provider.Resolve(typeof(T), parameters); - } - - /// - /// Resolves a given - /// - /// The service - /// The current - /// The service name/key used when registering the - /// Typed parameters to use when resolving the Service - /// The resolved Service - public static T Resolve(this IContainerProvider provider, string name, params (Type Type, object Instance)[] parameters) - { - return (T)provider.Resolve(typeof(T), name, parameters); - } - - /// - /// Resolves a given - /// - /// The service - /// The current - /// The service name/key used when registering the - /// The resolved Service - public static T Resolve(this IContainerProvider provider, string name) - { - return (T)provider.Resolve(typeof(T), name); - } - - /// - /// Determines if a given service is registered - /// - /// The service - /// The instance of the - /// true if the service is registered. - public static bool IsRegistered(this IContainerProvider containerProvider) - { - return containerProvider.IsRegistered(typeof(T)); - } - - internal static bool IsRegistered(this IContainerProvider containerProvider, Type type) - { - if (containerProvider is IContainerRegistry containerRegistry) - return containerRegistry.IsRegistered(type); - return false; - } - - /// - /// Determines if a given service is registered with the specified name - /// - /// The service - /// The instance of the - /// The service name or key used - /// true if the service is registered. - public static bool IsRegistered(this IContainerProvider containerProvider, string name) - { - return containerProvider.IsRegistered(typeof(T), name); - } - - internal static bool IsRegistered(this IContainerProvider containerProvider, Type type, string name) - { - if (containerProvider is IContainerRegistry containerRegistry) - return containerRegistry.IsRegistered(type, name); - return false; - } - } -} diff --git a/src/Prism.Core/Ioc/IContainerRegistry.cs b/src/Prism.Core/Ioc/IContainerRegistry.cs deleted file mode 100644 index 90a4b99426..0000000000 --- a/src/Prism.Core/Ioc/IContainerRegistry.cs +++ /dev/null @@ -1,150 +0,0 @@ -using System; - -namespace Prism.Ioc -{ - /// - /// The registering container - /// - public interface IContainerRegistry - { - /// - /// Registers an instance of a given - /// - /// The service that is being registered - /// The instance of the service or - /// The instance - IContainerRegistry RegisterInstance(Type type, object instance); - - /// - /// Registers an instance of a given with the specified name or key - /// - /// The service that is being registered - /// The instance of the service or - /// The name or key to register the service - /// The instance - IContainerRegistry RegisterInstance(Type type, object instance, string name); - - /// - /// Registers a Singleton with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The instance - IContainerRegistry RegisterSingleton(Type from, Type to); - - /// - /// Registers a Singleton with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The name or key to register the service - /// The instance - IContainerRegistry RegisterSingleton(Type from, Type to, string name); - - /// - /// Registers a Singleton with the given service factory delegate method. - /// - /// The service - /// The delegate method. - /// The instance - IContainerRegistry RegisterSingleton(Type type, Func factoryMethod); - - /// - /// Registers a Singleton with the given service factory delegate method. - /// - /// The service - /// The delegate method using . - /// The instance - IContainerRegistry RegisterSingleton(Type type, Func factoryMethod); - - /// - /// Registers a Singleton Service which implements service interfaces - /// - /// The implementation . - /// The service 's. - /// The instance - /// Registers all interfaces if none are specified. - IContainerRegistry RegisterManySingleton(Type type, params Type[] serviceTypes); - - /// - /// Registers a Transient with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The instance - IContainerRegistry Register(Type from, Type to); - - /// - /// Registers a Transient with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The name or key to register the service - /// The instance - IContainerRegistry Register(Type from, Type to, string name); - - /// - /// Registers a Transient Service using a delegate method - /// - /// The service - /// The delegate method. - /// The instance - IContainerRegistry Register(Type type, Func factoryMethod); - - /// - /// Registers a Transient Service using a delegate method - /// - /// The service - /// The delegate method using . - /// The instance - IContainerRegistry Register(Type type, Func factoryMethod); - - /// - /// Registers a Transient Service which implements service interfaces - /// - /// The implementing . - /// The service 's. - /// The instance - /// Registers all interfaces if none are specified. - IContainerRegistry RegisterMany(Type type, params Type[] serviceTypes); - - /// - /// Registers a scoped service - /// - /// The service - /// The implementation - /// The instance - IContainerRegistry RegisterScoped(Type from, Type to); - - /// - /// Registers a scoped service using a delegate method. - /// - /// The service - /// The delegate method. - /// The instance - IContainerRegistry RegisterScoped(Type type, Func factoryMethod); - - /// - /// Registers a scoped service using a delegate method. - /// - /// The service . - /// The delegate method. - /// The instance - IContainerRegistry RegisterScoped(Type type, Func factoryMethod); - - /// - /// Determines if a given service is registered - /// - /// The service - /// true if the service is registered. - bool IsRegistered(Type type); - - /// - /// Determines if a given service is registered with the specified name - /// - /// The service - /// The service name or key used - /// true if the service is registered. - bool IsRegistered(Type type, string name); - } -} diff --git a/src/Prism.Core/Ioc/IContainerRegistryExtensions.cs b/src/Prism.Core/Ioc/IContainerRegistryExtensions.cs deleted file mode 100644 index 18c57c5945..0000000000 --- a/src/Prism.Core/Ioc/IContainerRegistryExtensions.cs +++ /dev/null @@ -1,444 +0,0 @@ -using System; - -namespace Prism.Ioc -{ - /// - /// Provides Generic Type extensions for the - /// - public static class IContainerRegistryExtensions - { - /// - /// Will try to register the service if it has not already been registered - /// - /// The service type. - /// The implementation type. - /// The . - /// The . - public static IContainerRegistry TryRegister(this IContainerRegistry containerRegistry, Type from, Type to) - { - if (!containerRegistry.IsRegistered(from)) - containerRegistry.Register(from, to); - - return containerRegistry; - } - - /// - /// Will try to register the service if it has not already been registered - /// - /// The service type. - /// The implementation type. - /// The . - /// The . - public static IContainerRegistry TryRegister(this IContainerRegistry containerRegistry) - where TTo : TFrom - { - return containerRegistry.TryRegister(typeof(TFrom), typeof(TTo)); - } - - /// - /// Will try to register the service if it has not already been registered - /// - /// The service type. - /// The . - /// The . - public static IContainerRegistry TryRegister(this IContainerRegistry containerRegistry) - where T : class - { - return containerRegistry.TryRegister(typeof(T), typeof(T)); - } - - /// - /// Will try to register the service if it has not already been registered - /// - /// The service type. - /// The implementation type. - /// The . - /// The . - public static IContainerRegistry TryRegisterScoped(this IContainerRegistry containerRegistry, Type from, Type to) - { - if (!containerRegistry.IsRegistered(from)) - containerRegistry.RegisterScoped(from, to); - - return containerRegistry; - } - - /// - /// Will try to register the service if it has not already been registered - /// - /// The service type. - /// The . - /// The . - public static IContainerRegistry TryRegisterScoped(this IContainerRegistry containerRegistry) - where T : class - { - return containerRegistry.TryRegisterScoped(typeof(T), typeof(T)); - } - - /// - /// Will try to register the service if it has not already been registered - /// - /// The service type. - /// The implementation type. - /// The . - /// The . - public static IContainerRegistry TryRegisterScoped(this IContainerRegistry containerRegistry) - where TTo : TFrom - { - return containerRegistry.TryRegisterScoped(typeof(TFrom), typeof(TTo)); - } - - /// - /// Will try to register the service if it has not already been registered - /// - /// The service type. - /// The implementation type. - /// The . - /// The . - public static IContainerRegistry TryRegisterSingleton(this IContainerRegistry containerRegistry, Type from, Type to) - { - if (!containerRegistry.IsRegistered(from)) - containerRegistry.RegisterSingleton(from, to); - - return containerRegistry; - } - - /// - /// Will try to register the service if it has not already been registered - /// - /// The service type. - /// The implementation type. - /// The . - /// The . - public static IContainerRegistry TryRegisterSingleton(this IContainerRegistry containerRegistry) - where TTo : TFrom - { - return containerRegistry.TryRegisterSingleton(typeof(TFrom), typeof(TTo)); - } - - /// - /// Will try to register the service if it has not already been registered - /// - /// The service type. - /// The . - /// The . - public static IContainerRegistry TryRegisterSingleton(this IContainerRegistry containerRegistry) - where T : class - { - return containerRegistry.TryRegisterSingleton(typeof(T), typeof(T)); - } - - /// - /// Will try to register the service if it has not already been registered - /// - /// The service type. - /// The . - /// An instance of the service. - /// The . - public static IContainerRegistry TryRegisterInstance(this IContainerRegistry containerRegistry, T instance) - { - if (!containerRegistry.IsRegistered()) - containerRegistry.RegisterInstance(instance); - - return containerRegistry; - } - - /// - /// Registers an instance of a given - /// - /// The service that is being registered - /// The instance of the - /// The instance of the service or - /// The instance - public static IContainerRegistry RegisterInstance(this IContainerRegistry containerRegistry, TInterface instance) - { - return containerRegistry.RegisterInstance(typeof(TInterface), instance); - } - - /// - /// Registers an instance of a given with the specified name or key - /// - /// The service that is being registered - /// The instance of the - /// The instance of the service or - /// The name or key to register the service - /// The instance - public static IContainerRegistry RegisterInstance(this IContainerRegistry containerRegistry, TInterface instance, string name) - { - return containerRegistry.RegisterInstance(typeof(TInterface), instance, name); - } - - /// - /// Registers a Singleton with the given . - /// - /// The instance of the - /// The concrete - /// The instance - public static IContainerRegistry RegisterSingleton(this IContainerRegistry containerRegistry, Type type) - { - return containerRegistry.RegisterSingleton(type, type); - } - - /// - /// Registers a Singleton with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The instance of the - /// The instance - public static IContainerRegistry RegisterSingleton(this IContainerRegistry containerRegistry) where TTo : TFrom - { - return containerRegistry.RegisterSingleton(typeof(TFrom), typeof(TTo)); - } - - /// - /// Registers a Singleton with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The instance of the - /// The name or key to register the service - /// The instance - public static IContainerRegistry RegisterSingleton(this IContainerRegistry containerRegistry, string name) where TTo : TFrom - { - return containerRegistry.RegisterSingleton(typeof(TFrom), typeof(TTo), name); - } - - /// - /// Registers a Singleton with the given . - /// - /// The instance of the - /// The concrete - /// The instance - public static IContainerRegistry RegisterSingleton(this IContainerRegistry containerRegistry) - { - return containerRegistry.RegisterSingleton(typeof(T)); - } - - /// - /// Registers a Singleton with the given service factory delegate method. - /// - /// The service - /// The instance of the - /// The delegate method. - /// The instance - public static IContainerRegistry RegisterSingleton(this IContainerRegistry containerRegistry, Func factoryMethod) - { - return containerRegistry.RegisterSingleton(typeof(T), factoryMethod); - } - - /// - /// Registers a Singleton with the given service factory delegate method. - /// - /// The service - /// The instance of the - /// The delegate method using . - /// The instance - public static IContainerRegistry RegisterSingleton(this IContainerRegistry containerRegistry, Func factoryMethod) - { - return containerRegistry.RegisterSingleton(typeof(T), factoryMethod); - } - - /// - /// Registers a Singleton Service which implements service interfaces - /// - /// The implementation . - /// The instance of the - /// The service 's. - /// The instance - /// Registers all interfaces if none are specified. - public static IContainerRegistry RegisterManySingleton(this IContainerRegistry containerRegistry, params Type[] serviceTypes) - { - return containerRegistry.RegisterManySingleton(typeof(T), serviceTypes); - } - - /// - /// Registers a Transient with the given . - /// - /// The instance of the - /// The concrete - /// The instance - public static IContainerRegistry Register(this IContainerRegistry containerRegistry, Type type) - { - return containerRegistry.Register(type, type); - } - - /// - /// Registers a Transient with the given . - /// - /// The instance of the - /// The concrete - /// The instance - public static IContainerRegistry Register(this IContainerRegistry containerRegistry) - { - return containerRegistry.Register(typeof(T)); - } - - /// - /// Registers a Transient with the given . - /// - /// The instance of the - /// The concrete - /// The name or key to register the service - /// The instance - public static IContainerRegistry Register(this IContainerRegistry containerRegistry, Type type, string name) - { - return containerRegistry.Register(type, type, name); - } - - /// - /// Registers a Singleton with the given . - /// - /// The instance of the - /// The concrete - /// The name or key to register the service - /// The instance - public static IContainerRegistry Register(this IContainerRegistry containerRegistry, string name) - { - return containerRegistry.Register(typeof(T), name); - } - - /// - /// Registers a Transient with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The instance of the - /// The instance - public static IContainerRegistry Register(this IContainerRegistry containerRegistry) where TTo : TFrom - { - return containerRegistry.Register(typeof(TFrom), typeof(TTo)); - } - - /// - /// Registers a Transient with the given service and mapping to the specified implementation . - /// - /// The service - /// The implementation - /// The instance of the - /// The name or key to register the service - /// The instance - public static IContainerRegistry Register(this IContainerRegistry containerRegistry, string name) where TTo : TFrom - { - return containerRegistry.Register(typeof(TFrom), typeof(TTo), name); - } - - /// - /// Registers a Transient Service using a delegate method - /// - /// The service - /// The instance of the - /// The delegate method. - /// The instance - public static IContainerRegistry Register(this IContainerRegistry containerRegistry, Func factoryMethod) - { - return containerRegistry.Register(typeof(T), factoryMethod); - } - - /// - /// Registers a Transient Service using a delegate method - /// - /// The service - /// The instance of the - /// The delegate method using . - /// The instance - public static IContainerRegistry Register(this IContainerRegistry containerRegistry, Func factoryMethod) - { - return containerRegistry.Register(typeof(T), factoryMethod); - } - - /// - /// Registers a Transient Service which implements service interfaces - /// - /// The implementing - /// The instance of the - /// The service 's. - /// The instance - /// Registers all interfaces if none are specified. - public static IContainerRegistry RegisterMany(this IContainerRegistry containerRegistry, params Type[] serviceTypes) - { - return containerRegistry.RegisterMany(typeof(T), serviceTypes); - } - - /// - /// Registers a scoped service. - /// - /// The instance of the - /// The concrete . - /// The instance - public static IContainerRegistry RegisterScoped(this IContainerRegistry containerRegistry, Type type) - { - return containerRegistry.RegisterScoped(type, type); - } - - /// - /// Registers a scoped service. - /// - /// The service - /// The instance of the - /// The instance - public static IContainerRegistry RegisterScoped(this IContainerRegistry containerRegistry) - { - return containerRegistry.RegisterScoped(typeof(T)); - } - - /// - /// Registers a scoped service - /// - /// The service - /// The implementation - /// The instance of the - /// The instance - public static IContainerRegistry RegisterScoped(this IContainerRegistry containerRegistry) - where TTo : TFrom - { - return containerRegistry.RegisterScoped(typeof(TFrom), typeof(TTo)); - } - - /// - /// Registers a scoped service using a delegate method. - /// - /// The service - /// The instance of the - /// The delegate method. - /// The instance - public static IContainerRegistry RegisterScoped(this IContainerRegistry containerRegistry, Func factoryMethod) - { - return containerRegistry.RegisterScoped(typeof(T), factoryMethod); - } - - /// - /// Registers a scoped service using a delegate method. - /// - /// The service - /// The instance of the - /// The delegate method. - /// The instance - public static IContainerRegistry RegisterScoped(this IContainerRegistry containerRegistry, Func factoryMethod) - { - return containerRegistry.RegisterScoped(typeof(T), factoryMethod); - } - - /// - /// Determines if a given service is registered - /// - /// The service - /// The instance of the - /// true if the service is registered. - public static bool IsRegistered(this IContainerRegistry containerRegistry) - { - return containerRegistry.IsRegistered(typeof(T)); - } - - /// - /// Determines if a given service is registered with the specified name - /// - /// The service - /// The instance of the - /// The service name or key used - /// true if the service is registered. - public static bool IsRegistered(this IContainerRegistry containerRegistry, string name) - { - return containerRegistry.IsRegistered(typeof(T), name); - } - } -} diff --git a/src/Prism.Core/Ioc/IScopedProvider.cs b/src/Prism.Core/Ioc/IScopedProvider.cs deleted file mode 100644 index bbf3dcc99c..0000000000 --- a/src/Prism.Core/Ioc/IScopedProvider.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; - -namespace Prism.Ioc -{ - /// - /// Defines a Container Scope - /// - public interface IScopedProvider : IContainerProvider, IDisposable - { - /// - /// Gets or Sets the IsAttached property. - /// - /// - /// Indicates that Prism is tracking the scope - /// - bool IsAttached { get; set; } - } -} diff --git a/src/Prism.Core/Ioc/Internals/IContainerInfo.cs b/src/Prism.Core/Ioc/Internals/IContainerInfo.cs deleted file mode 100644 index d61d78e90b..0000000000 --- a/src/Prism.Core/Ioc/Internals/IContainerInfo.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Prism.Ioc.Internals -{ - /// - /// Used to resolve the registered implementation type for a given key - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IContainerInfo - { - /// - /// Locates the registered implementation for a give key - /// - /// Registration Key - /// Implementation - [EditorBrowsable(EditorBrowsableState.Never)] - Type GetRegistrationType(string key); - - /// - /// Locates the registered implementation for a give key - /// - /// Service Type - /// Implementation - [EditorBrowsable(EditorBrowsableState.Never)] - Type GetRegistrationType(Type serviceType); - } -} diff --git a/src/Prism.Core/Ioc/Internals/IContainerInfoExtensions.cs b/src/Prism.Core/Ioc/Internals/IContainerInfoExtensions.cs deleted file mode 100644 index efb8939c2c..0000000000 --- a/src/Prism.Core/Ioc/Internals/IContainerInfoExtensions.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Prism.Ioc.Internals -{ - /// - /// Internal extensions to get the registered implementation for Regions - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public static class IContainerInfoExtensions - { - /// - /// Locates the registered implementation for a give key - /// - /// The - /// Registration Key - /// Implementation - [EditorBrowsable(EditorBrowsableState.Never)] - public static Type GetRegistrationType(this IContainerExtension container, string key) - { - if (container is IContainerInfo ci) - return ci.GetRegistrationType(key); - - return null; - } - - /// - /// Locates the registered implementation for a give key - /// - /// The - /// Service Type - /// Implementation - [EditorBrowsable(EditorBrowsableState.Never)] - public static Type GetRegistrationType(this IContainerExtension container, Type - type) - { - if (container is IContainerInfo ci) - return ci.GetRegistrationType(type); - - return null; - } - } -} diff --git a/src/Prism.Core/Prism.Core.csproj b/src/Prism.Core/Prism.Core.csproj index 3fa161c74c..deb8534c3a 100644 --- a/src/Prism.Core/Prism.Core.csproj +++ b/src/Prism.Core/Prism.Core.csproj @@ -10,6 +10,10 @@ Prism is a fully open source version of the Prism guidance originally produced by Microsoft Patterns & Practices. Prism provides an implementation of a collection of design patterns that are helpful in writing well structured and maintainable XAML applications, including MVVM, dependency injection, commanding, event aggregation, and more. Prism's core functionality is a shared code base in a Portable Class Library targeting these platforms; WPF, and Xamarin Forms. Features that need to be platform specific are implemented in the respective libraries for the target platform. prism;wpf;xamarin;dotnet maui;maui;uno;unoplatform;mvvm;xaml + + + + diff --git a/src/Uno/Prism.DryIoc.Uno/Prism.DryIoc.Uno.WinUI.csproj b/src/Uno/Prism.DryIoc.Uno/Prism.DryIoc.Uno.WinUI.csproj index eab62a0b41..6138be3a48 100644 --- a/src/Uno/Prism.DryIoc.Uno/Prism.DryIoc.Uno.WinUI.csproj +++ b/src/Uno/Prism.DryIoc.Uno/Prism.DryIoc.Uno.WinUI.csproj @@ -34,6 +34,10 @@ Prism provides an implementation of a collection of design patterns that are hel + + + + @@ -44,17 +48,7 @@ Prism provides an implementation of a collection of design patterns that are hel - - - - - - - - - - diff --git a/src/Uno/Prism.Uno/Ioc/PrismServiceProviderFactory.cs b/src/Uno/Prism.Uno/Ioc/PrismServiceProviderFactory.cs deleted file mode 100644 index 3d2340438c..0000000000 --- a/src/Uno/Prism.Uno/Ioc/PrismServiceProviderFactory.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace Prism.Ioc; - -public class PrismServiceProviderFactory : IServiceProviderFactory -{ - private readonly IContainerExtension _containerExtension; - public PrismServiceProviderFactory(IContainerExtension containerExtension) - { - _containerExtension = containerExtension; - } - - public IContainerExtension CreateBuilder(IServiceCollection services) - { - _containerExtension.Populate(services); - return _containerExtension; - } - - public IServiceProvider CreateServiceProvider(IContainerExtension containerExtension) - { - return containerExtension.CreateServiceProvider(); - } -} diff --git a/src/Uno/Prism.Uno/Prism.Uno.WinUI.csproj b/src/Uno/Prism.Uno/Prism.Uno.WinUI.csproj index dffe8ac177..05a2d5153e 100644 --- a/src/Uno/Prism.Uno/Prism.Uno.WinUI.csproj +++ b/src/Uno/Prism.Uno/Prism.Uno.WinUI.csproj @@ -66,10 +66,6 @@ - - - - diff --git a/src/Uno/Prism.Uno/PrismApplicationBase.cs b/src/Uno/Prism.Uno/PrismApplicationBase.cs index 4160a15611..ab423a2964 100644 --- a/src/Uno/Prism.Uno/PrismApplicationBase.cs +++ b/src/Uno/Prism.Uno/PrismApplicationBase.cs @@ -100,7 +100,7 @@ protected virtual void ConfigureServices(IServiceCollection services) { } /// protected virtual void Initialize(IApplicationBuilder builder) { - ContainerLocator.SetContainerExtension(CreateContainerExtension); + ContainerLocator.SetContainerExtension(CreateContainerExtension()); _containerExtension = ContainerLocator.Current; ConfigureApp(builder); builder.Configure(ConfigureHost) diff --git a/src/Wpf/Prism.DryIoc.Wpf/Prism.DryIoc.Wpf.csproj b/src/Wpf/Prism.DryIoc.Wpf/Prism.DryIoc.Wpf.csproj index f259a72ab3..5b10a86ef7 100644 --- a/src/Wpf/Prism.DryIoc.Wpf/Prism.DryIoc.Wpf.csproj +++ b/src/Wpf/Prism.DryIoc.Wpf/Prism.DryIoc.Wpf.csproj @@ -12,7 +12,7 @@ - + @@ -24,6 +24,4 @@ - - diff --git a/src/Wpf/Prism.DryIoc.Wpf/PrismApplication.cs b/src/Wpf/Prism.DryIoc.Wpf/PrismApplication.cs index 42d2d911a5..432013a49d 100644 --- a/src/Wpf/Prism.DryIoc.Wpf/PrismApplication.cs +++ b/src/Wpf/Prism.DryIoc.Wpf/PrismApplication.cs @@ -1,7 +1,7 @@ using System; using DryIoc; +using Prism.Container.DryIoc; using Prism.Ioc; -using Prism.Navigation.Regions; using ExceptionExtensions = System.ExceptionExtensions; namespace Prism.DryIoc @@ -23,7 +23,7 @@ public abstract class PrismApplication : PrismApplicationBase /// A new . protected override IContainerExtension CreateContainerExtension() { - return new DryIocContainerExtension(new Container(CreateContainerRules())); + return new DryIocContainerExtension(CreateContainerRules()); } /// diff --git a/src/Wpf/Prism.DryIoc.Wpf/PrismBootstrapper.cs b/src/Wpf/Prism.DryIoc.Wpf/PrismBootstrapper.cs index 19d5a521d1..6ea9bf6083 100644 --- a/src/Wpf/Prism.DryIoc.Wpf/PrismBootstrapper.cs +++ b/src/Wpf/Prism.DryIoc.Wpf/PrismBootstrapper.cs @@ -1,5 +1,6 @@ using System; using DryIoc; +using Prism.Container.DryIoc; using Prism.Ioc; namespace Prism.DryIoc @@ -21,7 +22,7 @@ public abstract class PrismBootstrapper : PrismBootstrapperBase /// A new . protected override IContainerExtension CreateContainerExtension() { - return new DryIocContainerExtension(new Container(CreateContainerRules())); + return new DryIocContainerExtension(CreateContainerRules()); } /// diff --git a/src/Wpf/Prism.Unity.Wpf/Prism.Unity.Wpf.csproj b/src/Wpf/Prism.Unity.Wpf/Prism.Unity.Wpf.csproj index 558166be04..d083b7e495 100644 --- a/src/Wpf/Prism.Unity.Wpf/Prism.Unity.Wpf.csproj +++ b/src/Wpf/Prism.Unity.Wpf/Prism.Unity.Wpf.csproj @@ -12,7 +12,7 @@ - + @@ -26,6 +26,4 @@ - - diff --git a/src/Wpf/Prism.Unity.Wpf/PrismApplication.cs b/src/Wpf/Prism.Unity.Wpf/PrismApplication.cs index 5bc0e791e4..55d863ba35 100644 --- a/src/Wpf/Prism.Unity.Wpf/PrismApplication.cs +++ b/src/Wpf/Prism.Unity.Wpf/PrismApplication.cs @@ -1,4 +1,5 @@ using System; +using Prism.Container.Unity; using Prism.Ioc; using Unity; diff --git a/src/Wpf/Prism.Unity.Wpf/PrismBootstrapper.cs b/src/Wpf/Prism.Unity.Wpf/PrismBootstrapper.cs index 60590e11b9..945331403a 100644 --- a/src/Wpf/Prism.Unity.Wpf/PrismBootstrapper.cs +++ b/src/Wpf/Prism.Unity.Wpf/PrismBootstrapper.cs @@ -1,4 +1,5 @@ using System; +using Prism.Container.Unity; using Prism.Ioc; using Unity; diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/DelayedRegionCreationBehavior.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/DelayedRegionCreationBehavior.cs index 994fbc4d0e..85ce900f92 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/DelayedRegionCreationBehavior.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/DelayedRegionCreationBehavior.cs @@ -35,7 +35,7 @@ public class DelayedRegionCreationBehavior /// /// /// The region adapter mappings, that are used to find the correct adapter for - /// a given controltype. The controltype is determined by the value. + /// a given control type. The control type is determined by the value. /// public DelayedRegionCreationBehavior(RegionAdapterMappings regionAdapterMappings) { diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs index fea6bd0e6a..f843dbdc3d 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs @@ -30,7 +30,6 @@ public class Region : IRegion private object _context; private IRegionManager _regionManager; private IRegionNavigationService _regionNavigationService; - private IContainerProvider _container; private Comparison _sort; @@ -40,7 +39,6 @@ public class Region : IRegion public Region() { Behaviors = new RegionBehaviorCollection(this); - _container = ContainerLocator.Container; _sort = DefaultSortComparison; } @@ -217,10 +215,7 @@ protected virtual ObservableCollection ItemMetadataCollection { get { - if (_itemMetadataCollection == null) - { - _itemMetadataCollection = new ObservableCollection(); - } + _itemMetadataCollection ??= new ObservableCollection(); return _itemMetadataCollection; } @@ -234,7 +229,7 @@ protected virtual ObservableCollection ItemMetadataCollection /// The that is set on the view if it is a . It will be the current region manager when using this overload. public IRegionManager Add(string viewName) { - var view = _container.Resolve(viewName); + var view = ContainerLocator.Container.Resolve(viewName); return Add(view, viewName, false); } diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/RegionNavigationContentLoader.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/RegionNavigationContentLoader.cs index e01de9f7ba..65e17c545d 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/RegionNavigationContentLoader.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/RegionNavigationContentLoader.cs @@ -176,7 +176,7 @@ protected virtual IEnumerable GetCandidatesFromRegion(IRegion region, st private IEnumerable GetCandidatesFromRegionViews(IRegion region, string candidateNavigationContract) { - return region.Views.Where(v => ViewIsMatch(v.GetType(), candidateNavigationContract)); + return region.Views.Where(v => v is not null && ViewIsMatch(v.GetType(), candidateNavigationContract)); } private static bool ViewIsMatch(Type viewType, string navigationSegment) diff --git a/src/Wpf/Prism.Wpf/PrismApplicationBase.cs b/src/Wpf/Prism.Wpf/PrismApplicationBase.cs index 3ccd861f9e..ce6a615f24 100644 --- a/src/Wpf/Prism.Wpf/PrismApplicationBase.cs +++ b/src/Wpf/Prism.Wpf/PrismApplicationBase.cs @@ -56,7 +56,7 @@ protected virtual void ConfigureViewModelLocator() /// protected virtual void Initialize() { - ContainerLocator.SetContainerExtension(CreateContainerExtension); + ContainerLocator.SetContainerExtension(CreateContainerExtension()); _containerExtension = ContainerLocator.Current; _moduleCatalog = CreateModuleCatalog(); RegisterRequiredTypes(_containerExtension); diff --git a/src/Wpf/Prism.Wpf/PrismBootstrapperBase.cs b/src/Wpf/Prism.Wpf/PrismBootstrapperBase.cs index 9a74a34ee9..e1d9cc386d 100644 --- a/src/Wpf/Prism.Wpf/PrismBootstrapperBase.cs +++ b/src/Wpf/Prism.Wpf/PrismBootstrapperBase.cs @@ -53,7 +53,7 @@ protected virtual void ConfigureViewModelLocator() /// protected virtual void Initialize() { - ContainerLocator.SetContainerExtension(CreateContainerExtension); + ContainerLocator.SetContainerExtension(CreateContainerExtension()); _containerExtension = ContainerLocator.Current; _moduleCatalog = CreateModuleCatalog(); RegisterRequiredTypes(_containerExtension); diff --git a/tests/Containers/Prism.Container.DryIoc.Tests/ContainerHelpers.cs b/tests/Containers/Prism.Container.DryIoc.Tests/ContainerHelpers.cs deleted file mode 100644 index 453686d685..0000000000 --- a/tests/Containers/Prism.Container.DryIoc.Tests/ContainerHelpers.cs +++ /dev/null @@ -1,10 +0,0 @@ -using DryIoc; - -namespace Prism.Ioc.Tests -{ - public static class ContainerHelpers - { - public static IContainer GetContainer(this IContainerExtension container) => - Prism.DryIoc.PrismIocExtensions.GetContainer((IContainerProvider)container); - } -} diff --git a/tests/Containers/Prism.Container.DryIoc.Tests/ContainerSetup.cs b/tests/Containers/Prism.Container.DryIoc.Tests/ContainerSetup.cs deleted file mode 100644 index 4155270132..0000000000 --- a/tests/Containers/Prism.Container.DryIoc.Tests/ContainerSetup.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using DryIoc; -using Prism.DryIoc; - -namespace Prism.Ioc.Tests -{ - partial class ContainerSetup - { - protected virtual IContainerExtension CreateContainerInternal() => new DryIocContainerExtension(); - - public Type NativeContainerType => typeof(IContainer); - } -} diff --git a/tests/Containers/Prism.Container.DryIoc.Tests/ContainerSetupWithDefaultSingleton.cs b/tests/Containers/Prism.Container.DryIoc.Tests/ContainerSetupWithDefaultSingleton.cs deleted file mode 100644 index 138a47150a..0000000000 --- a/tests/Containers/Prism.Container.DryIoc.Tests/ContainerSetupWithDefaultSingleton.cs +++ /dev/null @@ -1,13 +0,0 @@ -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)); - } -} diff --git a/tests/Containers/Prism.Container.DryIoc.Tests/ContainerTestsWithDefaultSingleton.cs b/tests/Containers/Prism.Container.DryIoc.Tests/ContainerTestsWithDefaultSingleton.cs deleted file mode 100644 index 22c0f304a2..0000000000 --- a/tests/Containers/Prism.Container.DryIoc.Tests/ContainerTestsWithDefaultSingleton.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using Prism.Ioc.Mocks.Services; -using Prism.Ioc.Tests; -using Xunit; - -namespace Prism.Ioc.DryIoc.Tests -{ - public class ContainerTestsWithDefaultSingleton : IClassFixture, 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(); - var resolved1 = container.Resolve(); - var resolved2 = container.Resolve(); - Assert.NotNull(resolved1); - Assert.NotNull(resolved2); - Assert.IsType(resolved1); - Assert.IsType(resolved2); - Assert.NotSame(resolved1, resolved2); - } - - [Fact] - public void RegisterNamedServiceMappingCreatesTransient() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register("Test"); - var resolved1 = container.Resolve("Test"); - var resolved2 = container.Resolve("Test"); - var ex = Record.Exception(() => container.Resolve()); - Assert.NotNull(ex); - Assert.NotNull(resolved1); - Assert.NotNull(resolved2); - Assert.IsType(resolved1); - Assert.IsType(resolved2); - Assert.NotSame(resolved1, resolved2); - } - - [Fact] - public void AutomaticTransientResolutionOfConcreteType() - { - var container = Setup.CreateContainer(); - var resolved1 = container.Resolve(); - var resolved2 = container.Resolve(); - 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); - } - } -} diff --git a/tests/Containers/Prism.Container.DryIoc.Tests/Prism.Ioc.DryIoc.Tests.csproj b/tests/Containers/Prism.Container.DryIoc.Tests/Prism.Ioc.DryIoc.Tests.csproj deleted file mode 100644 index 8c90bf8649..0000000000 --- a/tests/Containers/Prism.Container.DryIoc.Tests/Prism.Ioc.DryIoc.Tests.csproj +++ /dev/null @@ -1,37 +0,0 @@ - - - - net6.0 - false - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - all - runtime; build; native; contentfiles; analyzers - - - - - - - - - - - - diff --git a/tests/Containers/Prism.Container.Shared/Mocks/Services/CompositeService.cs b/tests/Containers/Prism.Container.Shared/Mocks/Services/CompositeService.cs deleted file mode 100644 index 56f62c69d0..0000000000 --- a/tests/Containers/Prism.Container.Shared/Mocks/Services/CompositeService.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Prism.Ioc.Mocks.Services -{ - public class CompositeService : IServiceA, IServiceB, IServiceC - { - public IServiceB ServiceB => this; - } -} diff --git a/tests/Containers/Prism.Container.Shared/Mocks/Services/IServiceA.cs b/tests/Containers/Prism.Container.Shared/Mocks/Services/IServiceA.cs deleted file mode 100644 index 3b64867f4e..0000000000 --- a/tests/Containers/Prism.Container.Shared/Mocks/Services/IServiceA.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Prism.Ioc.Mocks.Services -{ - public interface IServiceA - { - } -} diff --git a/tests/Containers/Prism.Container.Shared/Mocks/Services/IServiceB.cs b/tests/Containers/Prism.Container.Shared/Mocks/Services/IServiceB.cs deleted file mode 100644 index 61d27a866d..0000000000 --- a/tests/Containers/Prism.Container.Shared/Mocks/Services/IServiceB.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Prism.Ioc.Mocks.Services -{ - public interface IServiceB - { - } -} diff --git a/tests/Containers/Prism.Container.Shared/Mocks/Services/IServiceC.cs b/tests/Containers/Prism.Container.Shared/Mocks/Services/IServiceC.cs deleted file mode 100644 index f5d34ea991..0000000000 --- a/tests/Containers/Prism.Container.Shared/Mocks/Services/IServiceC.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Prism.Ioc.Mocks.Services -{ - public interface IServiceC - { - IServiceB ServiceB { get; } - } -} diff --git a/tests/Containers/Prism.Container.Shared/Mocks/Services/ServiceA.cs b/tests/Containers/Prism.Container.Shared/Mocks/Services/ServiceA.cs deleted file mode 100644 index 27127e4c09..0000000000 --- a/tests/Containers/Prism.Container.Shared/Mocks/Services/ServiceA.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Prism.Ioc.Mocks.Services -{ - public class ServiceA : IServiceA - { - public string SomeProperty { get; set; } - } -} diff --git a/tests/Containers/Prism.Container.Shared/Mocks/Services/ServiceB.cs b/tests/Containers/Prism.Container.Shared/Mocks/Services/ServiceB.cs deleted file mode 100644 index e594f63c13..0000000000 --- a/tests/Containers/Prism.Container.Shared/Mocks/Services/ServiceB.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Prism.Ioc.Mocks.Services -{ - public class ServiceB : IServiceB - { - } -} diff --git a/tests/Containers/Prism.Container.Shared/Mocks/Services/ServiceC.cs b/tests/Containers/Prism.Container.Shared/Mocks/Services/ServiceC.cs deleted file mode 100644 index ac46806352..0000000000 --- a/tests/Containers/Prism.Container.Shared/Mocks/Services/ServiceC.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Prism.Ioc.Mocks.Services -{ - public class ServiceC : IServiceC - { - public ServiceC(IServiceB serviceB) - { - ServiceB = serviceB; - } - - public IServiceB ServiceB { get; } - } -} diff --git a/tests/Containers/Prism.Container.Shared/Mocks/ViewModels/ConstructorArgumentViewModel.cs b/tests/Containers/Prism.Container.Shared/Mocks/ViewModels/ConstructorArgumentViewModel.cs deleted file mode 100644 index 218cacc2f6..0000000000 --- a/tests/Containers/Prism.Container.Shared/Mocks/ViewModels/ConstructorArgumentViewModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Prism.Ioc.Mocks.Services; -using Prism.Mvvm; - -namespace Prism.Ioc.Mocks.ViewModels -{ - public class ConstructorArgumentViewModel : BindableBase - { - public IServiceA Service { get; } - - public ConstructorArgumentViewModel(IServiceA service) - { - Service = service; - } - } -} diff --git a/tests/Containers/Prism.Container.Shared/Mocks/Views/BadView.cs b/tests/Containers/Prism.Container.Shared/Mocks/Views/BadView.cs deleted file mode 100644 index 924b41201f..0000000000 --- a/tests/Containers/Prism.Container.Shared/Mocks/Views/BadView.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -namespace Prism.Ioc.Mocks.Views -{ - public class BadView : ViewBase - { - public BadView() - { - throw new XamlParseException("You write bad XAML"); - } - } - - public class XamlParseException : Exception - { - public XamlParseException(string message) - : base(message) - { - } - } -} diff --git a/tests/Containers/Prism.Container.Shared/Mocks/Views/ViewA.cs b/tests/Containers/Prism.Container.Shared/Mocks/Views/ViewA.cs deleted file mode 100644 index bc577f2449..0000000000 --- a/tests/Containers/Prism.Container.Shared/Mocks/Views/ViewA.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Prism.Ioc.Mocks.Views -{ - public class ViewA : ViewBase - { - } -} diff --git a/tests/Containers/Prism.Container.Shared/Mocks/Views/ViewB.cs b/tests/Containers/Prism.Container.Shared/Mocks/Views/ViewB.cs deleted file mode 100644 index 5b07592f76..0000000000 --- a/tests/Containers/Prism.Container.Shared/Mocks/Views/ViewB.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Prism.Ioc.Mocks.Views -{ - public class ViewB : ViewBase - { - } -} diff --git a/tests/Containers/Prism.Container.Shared/Mocks/Views/ViewBase.cs b/tests/Containers/Prism.Container.Shared/Mocks/Views/ViewBase.cs deleted file mode 100644 index 97329365cc..0000000000 --- a/tests/Containers/Prism.Container.Shared/Mocks/Views/ViewBase.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Prism.Ioc.Mocks.Views -{ - public class ViewBase - { - } -} diff --git a/tests/Containers/Prism.Container.Shared/Prism.Container.Shared.projitems b/tests/Containers/Prism.Container.Shared/Prism.Container.Shared.projitems deleted file mode 100644 index 0c6bb4dc66..0000000000 --- a/tests/Containers/Prism.Container.Shared/Prism.Container.Shared.projitems +++ /dev/null @@ -1,31 +0,0 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - true - 78932299-2281-4a59-bfb8-07de3014f748 - - - Prism.Ioc - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tests/Containers/Prism.Container.Shared/Prism.Ioc.Shared.shproj b/tests/Containers/Prism.Container.Shared/Prism.Ioc.Shared.shproj deleted file mode 100644 index 192f77f2f2..0000000000 --- a/tests/Containers/Prism.Container.Shared/Prism.Ioc.Shared.shproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - 78932299-2281-4a59-bfb8-07de3014f748 - 14.0 - - - - - - - - diff --git a/tests/Containers/Prism.Container.Shared/Tests/ContainerExtension.cs b/tests/Containers/Prism.Container.Shared/Tests/ContainerExtension.cs deleted file mode 100644 index 7c4121a2d1..0000000000 --- a/tests/Containers/Prism.Container.Shared/Tests/ContainerExtension.cs +++ /dev/null @@ -1,6 +0,0 @@ -using Xunit; - -namespace Prism.Ioc.Tests -{ - public class ContainerExtension { } -} diff --git a/tests/Containers/Prism.Container.Shared/Tests/ContainerExtensionCollection.cs b/tests/Containers/Prism.Container.Shared/Tests/ContainerExtensionCollection.cs deleted file mode 100644 index da36a82a63..0000000000 --- a/tests/Containers/Prism.Container.Shared/Tests/ContainerExtensionCollection.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Xunit; - -namespace Prism.Ioc.Tests -{ - [CollectionDefinition(nameof(ContainerExtension), DisableParallelization = true)] - public class ContainerExtensionCollection : ICollectionFixture - { - } -} diff --git a/tests/Containers/Prism.Container.Shared/Tests/ContainerFixture.cs b/tests/Containers/Prism.Container.Shared/Tests/ContainerFixture.cs deleted file mode 100644 index 099c7533f6..0000000000 --- a/tests/Containers/Prism.Container.Shared/Tests/ContainerFixture.cs +++ /dev/null @@ -1,778 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Prism.Ioc.Mocks.Services; -using Prism.Ioc.Mocks.Views; -using Xunit; - -namespace Prism.Ioc.Tests -{ - public class ContainerTests : TestBase - { - public ContainerTests(ContainerSetup setup) - : base(setup) - { - } - - [Fact] - public void IContainerProviderIsRegistered() - { - var container = Setup.CreateContainer(); - var resolved = container.Resolve(); - Assert.Same(container, resolved); - } - - [Fact] - public void IContainerExtensionIsRegistered() - { - var container = Setup.CreateContainer(); - var resolved = container.Resolve(); - Assert.Same(container, resolved); - } - - [Fact] - public void NativeContainerIsRegistered() - { - var container = Setup.CreateContainer(); - object resolved = null; - var ex = Record.Exception(() => resolved = container.Resolve(Setup.NativeContainerType)); - Assert.Null(ex); - Assert.NotNull(resolved); - Assert.IsAssignableFrom(Setup.NativeContainerType, resolved); - } - - [Fact] - public void RegisterInstanceReturnsSameInstance() - { - var instance = new ServiceA(); - var container = Setup.CreateContainer(); - Setup.Registry.RegisterInstance(instance); - object resolved = container.Resolve(); - Assert.Same(instance, resolved); - } - - [Fact] - public void RegisterNamedInstanceReturnsSameInstance() - { - var instance = new ServiceA(); - var container = Setup.CreateContainer(); - Setup.Registry.RegisterInstance(instance, "Test"); - var resolved = container.Resolve("Test"); - Assert.Same(instance, resolved); - } - - [Fact] - public void AutomaticTransientResolutionOfConcreteType() - { - var container = Setup.CreateContainer(); - var resolved1 = container.Resolve(); - var resolved2 = container.Resolve(); - Assert.NotNull(resolved1); - Assert.NotSame(resolved1, resolved2); - } - - [Fact] - public void RegisterConcreteTypeCreatesTransient() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register(); - var resolved1 = container.Resolve(); - var resolved2 = container.Resolve(); - Assert.NotNull(resolved1); - Assert.NotSame(resolved1, resolved2); - } - - [Fact] - public void RegisterNamedConcreteTypeCreatesTransient() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register("Test"); - var resolved1 = container.Resolve("Test"); - var resolved2 = container.Resolve("Test"); - Assert.NotNull(resolved1); - Assert.NotSame(resolved1, resolved2); - } - - [Fact] - public void RegisterServiceMappingCreatesTransient() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register(); - var resolved1 = container.Resolve(); - var resolved2 = container.Resolve(); - Assert.NotNull(resolved1); - Assert.NotNull(resolved2); - Assert.IsType(resolved1); - Assert.IsType(resolved2); - Assert.NotSame(resolved1, resolved2); - } - - [Fact] - public void RegisterNamedServiceMappingCreatesTransient() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register("Test"); - var resolved1 = container.Resolve("Test"); - var resolved2 = container.Resolve("Test"); - var ex = Record.Exception(() => container.Resolve()); - Assert.NotNull(ex); - Assert.NotNull(resolved1); - Assert.NotNull(resolved2); - Assert.IsType(resolved1); - Assert.IsType(resolved2); - Assert.NotSame(resolved1, resolved2); - } - - [Fact] - public void RegisterTransientWithFactory() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register(CreateService); - var resolved = container.Resolve(); - Assert.NotNull(resolved); - Assert.IsType(resolved); - var ServiceA = resolved as ServiceA; - Assert.Equal("Created through a factory", ServiceA.SomeProperty); - var resolved2 = container.Resolve(); - Assert.NotSame(resolved, resolved2); - } - - [Fact] - public void RegisterTransientWithFactoryAndContainerProvider() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register(nameof(ServiceA)); - Setup.Registry.Register(CreateServiceWithContainerProvider); - var resolved = container.Resolve(); - Assert.NotNull(resolved); - Assert.IsType(resolved); - var serviceA = resolved as ServiceA; - - var resolved2 = container.Resolve(); - Assert.NotSame(resolved, resolved2); - } - - [Fact] - public void RegisterManyRegistersAllInterfacesByDefault() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterMany(); - - Assert.IsType(container.Resolve()); - Assert.IsType(container.Resolve()); - Assert.IsType(container.Resolve()); - } - - [Fact] - public void RegisterManyOnlyRegistersSpecifiedInterfaces() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterMany(typeof(IServiceA), typeof(IServiceB)); - - Assert.IsType(container.Resolve()); - Assert.IsType(container.Resolve()); - var ex = Record.Exception(() => container.Resolve()); - Assert.NotNull(ex); - } - - [Fact] - public void RegisterManyRegistersServicesAsTransients() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterMany(); - Assert.NotSame(container.Resolve(), container.Resolve()); - } - - [Fact] - public void RegisterSupportsLazyInjection() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register(); - var lazy = container.Resolve>(); - Assert.NotNull(lazy); - Assert.False(lazy.IsValueCreated); - var instance = lazy.Value; - Assert.IsType(instance); - - var lazy2 = container.Resolve>(); - Assert.NotSame(instance, lazy2.Value); - } - - [Fact] - public void RegisterSupportsFuncInjection() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register(); - var func = container.Resolve>(); - Assert.NotNull(func); - var instance = func(); - Assert.IsType(instance); - - var func2 = container.Resolve>(); - Assert.NotSame(instance, func2()); - } - - [Fact] - public void RegisterSingletonConcreteTypeCreatesSingleton() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterSingleton(); - var resolved1 = container.Resolve(); - var resolved2 = container.Resolve(); - Assert.NotNull(resolved1); - Assert.Same(resolved1, resolved2); - } - - [Fact] - public void RegisterSingletonServiceMappingCreatesSingleton() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterSingleton(); - var resolved1 = container.Resolve(); - var resolved2 = container.Resolve(); - Assert.NotNull(resolved1); - Assert.NotNull(resolved2); - Assert.IsType(resolved1); - Assert.IsType(resolved2); - Assert.Same(resolved1, resolved2); - } - - [Fact] - public void RegisterSingletonNamedServiceMappingCreatesSingleton() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterSingleton("Test"); - var resolved1 = container.Resolve("Test"); - var resolved2 = container.Resolve("Test"); - var ex = Record.Exception(() => container.Resolve()); - Assert.NotNull(ex); - Assert.NotNull(resolved1); - Assert.NotNull(resolved2); - Assert.IsType(resolved1); - Assert.IsType(resolved2); - Assert.Same(resolved1, resolved2); - } - - [Fact] - public void RegisterSingletonWithFactory() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterSingleton(CreateService); - var resolved = container.Resolve(); - Assert.NotNull(resolved); - Assert.IsType(resolved); - var ServiceA = resolved as ServiceA; - Assert.Equal("Created through a factory", ServiceA.SomeProperty); - var resolved2 = container.Resolve(); - Assert.Same(resolved, resolved2); - } - - [Fact] - public void RegisterSingletonWithFactoryAndContainerProvider() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register(nameof(ServiceA)); - Setup.Registry.RegisterSingleton(CreateServiceWithContainerProvider); - var resolved = container.Resolve(); - Assert.NotNull(resolved); - Assert.IsType(resolved); - var serviceA = resolved as ServiceA; - var resolved2 = container.Resolve(); - Assert.Same(resolved, resolved2); - } - - [Fact] - public void RegisterManySingletonRegistersAllInterfacesByDefault() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterManySingleton(); - - Assert.IsType(container.Resolve()); - Assert.IsType(container.Resolve()); - Assert.IsType(container.Resolve()); - } - - [Fact] - public void RegisterManySingletonOnlyRegistersSpecifiedInterfaces() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterManySingleton(typeof(IServiceA), typeof(IServiceB)); - - Assert.IsType(container.Resolve()); - Assert.IsType(container.Resolve()); - var ex = Record.Exception(() => container.Resolve()); - Assert.NotNull(ex); - } - - [Fact] - public void RegisterManySingletonUsesSharedInstanceForAllServices() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterManySingleton(); - - var serviceA = container.Resolve(); - var serviceB = container.Resolve(); - var serviceC = container.Resolve(); - - Assert.Same(serviceA, serviceB); - Assert.Same(serviceB, serviceC); - } - - [Fact] - public void RegisterSingletonSupportsLazyInjection() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterSingleton(); - var lazy = container.Resolve>(); - Assert.NotNull(lazy); - Assert.False(lazy.IsValueCreated); - var instance = lazy.Value; - Assert.IsType(instance); - - var lazy2 = container.Resolve>(); - Assert.Same(instance, lazy2.Value); - } - - [Fact] - public void RegisterSingletonSupportsFuncInjection() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterSingleton(); - var func = container.Resolve>(); - Assert.NotNull(func); - var instance = func(); - Assert.IsType(instance); - - var func2 = container.Resolve>(); - Assert.Same(instance, func2()); - } - - [Fact] - public void RegisterScopedConcreteTypeCreatesScoped() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterScoped(); - var resolved1 = container.Resolve(); - var resolved2 = container.Resolve(); - - Assert.NotNull(resolved1); - Assert.Same(resolved1, resolved2); - - container.CreateScope(); - var resolved3 = container.Resolve(); - Assert.NotSame(resolved1, resolved3); - } - - [Fact] - public void RegisterScopedServiceMappingCreatesScoped() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterScoped(); - var resolved1 = container.Resolve(); - var resolved2 = container.Resolve(); - Assert.NotNull(resolved1); - Assert.NotNull(resolved2); - Assert.IsType(resolved1); - Assert.IsType(resolved2); - Assert.Same(resolved1, resolved2); - - container.CreateScope(); - var resolved3 = container.Resolve(); - Assert.NotSame(resolved1, resolved3); - } - - [Fact] - public void RegisterScopedWithFactory() - { - var container = Setup.CreateContainer(); - Setup.Registry.RegisterScoped(CreateService); - var resolved1 = container.Resolve(); - Assert.NotNull(resolved1); - Assert.IsType(resolved1); - var ServiceA = resolved1 as ServiceA; - Assert.Equal("Created through a factory", ServiceA.SomeProperty); - - var resolved2 = container.Resolve(); - Assert.Same(resolved1, resolved2); - container.CreateScope(); - var resolved3 = container.Resolve(); - Assert.NotSame(resolved2, resolved3); - } - - [Fact] - public void RegisterScopedWithFactoryAndContainerProvider() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register(nameof(ServiceA)); - Setup.Registry.RegisterScoped(CreateServiceWithContainerProvider); - var resolved1 = container.Resolve(); - Assert.NotNull(resolved1); - Assert.IsType(resolved1); - - var resolved2 = container.Resolve(); - Assert.Same(resolved1, resolved2); - container.CreateScope(); - var resolved3 = container.Resolve(); - Assert.NotSame(resolved2, resolved3); - } - - [Fact] - public void LocatesImplementationTypeForNamedService() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register(nameof(ViewA)); - var type = ((Internals.IContainerInfo)Setup.Extension).GetRegistrationType(nameof(ViewA)); - Assert.NotNull(type); - Assert.Equal(typeof(ViewA), type); - } - - [Fact] - public void LocatesImplementationType() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register(); - var type = ((Internals.IContainerInfo)Setup.Extension).GetRegistrationType(typeof(IServiceA)); - Assert.NotNull(type); - Assert.Equal(typeof(ServiceA), type); - } - - [Fact] - public void RegisterTransientDelegateReturnsNewInstanceEachTime() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register(() => new ServiceA()); - - Assert.NotSame(container.Resolve(), container.Resolve()); - } - - [Fact] - public void RegisterTransientDelegateWithContainerReturnsNewInstanceEachTime() - { - var container = Setup.CreateContainer(); - Setup.Registry.Register(x => new ServiceA()); - - Assert.NotSame(container.Resolve(), container.Resolve()); - } - - private static IServiceA CreateService() => - new ServiceA { SomeProperty = "Created through a factory" }; - - private static IServiceA CreateServiceWithContainerProvider(IContainerProvider containerProvider) => - containerProvider.Resolve(nameof(ServiceA)); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [Fact] - public void Register_RegistersTransientService() - { - Setup.CreateContainer(); - Setup.Registry.Register(); - - var resolve1 = Setup.Container.Resolve(); - var resolve2 = Setup.Container.Resolve(); - - Assert.IsType(resolve1); - Assert.NotSame(resolve1, resolve2); - } - - [Fact] - public void Register_RegistersFunc() - { - Setup.CreateContainer(); - Setup.Registry.Register(); - - var factory = Setup.Container.Resolve>(); - IServiceA service = null; - Assert.NotNull(factory); - var ex = Record.Exception(() => service = factory()); - Assert.Null(ex); - Assert.NotNull(service); - Assert.IsType(service); - Assert.NotSame(service, factory()); - } - - [Fact] - public void Register_RegistersLazy() - { - Setup.CreateContainer(); - Setup.Registry.Register(); - - var factory = Setup.Container.Resolve>(); - IServiceA service = null; - Assert.NotNull(factory); - var ex = Record.Exception(() => service = factory.Value); - Assert.Null(ex); - Assert.NotNull(service); - Assert.IsType(service); - Assert.NotSame(service, Setup.Container.Resolve>().Value); - } - -#if !UNITY - [Fact] - public void Register_RegistersIEnumerable() - { - Setup.CreateContainer(); - Setup.Registry.Register(); - var services = Setup.Container.Resolve>(); - - Assert.NotNull(services); - Assert.Single(services); - Assert.IsType(services.First()); - } -#endif - - [Fact] - public void Register_LastInFirstOut() - { - Setup.CreateContainer(); - Setup.Registry.RegisterSingleton(); - Setup.Registry.Register(); - var service = Setup.Container.Resolve(); - - Assert.IsType(service); - Assert.NotSame(service, Setup.Container.Resolve()); - } - -#if !UNITY - [Theory] - [InlineData(0, typeof(ServiceA))] - [InlineData(1, typeof(CompositeService))] - public void Register_ResolveAll(int index, Type type) - { - Setup.CreateContainer(); - Setup.Registry.Register(); - Setup.Registry.Register(); - var services = Setup.Container.Resolve>(); - - Assert.NotNull(services); - Assert.Equal(2, services.Count()); - Assert.IsType(type, services.ElementAt(index)); - } - -#endif - - [Fact] - public void RegisterSingleton_RegistersSingletonService() - { - Setup.CreateContainer(); - Setup.Registry.RegisterSingleton(); - - var resolve1 = Setup.Container.Resolve(); - var resolve2 = Setup.Container.Resolve(); - - Assert.IsType(resolve1); - Assert.Same(resolve1, resolve2); - } - - [Fact] - public void RegisterSinglton_RegistersFunc() - { - Setup.CreateContainer(); - Setup.Registry.RegisterSingleton(); - - var factory = Setup.Container.Resolve>(); - IServiceA service = null; - Assert.NotNull(factory); - var ex = Record.Exception(() => service = factory()); - Assert.Null(ex); - Assert.NotNull(service); - Assert.IsType(service); - Assert.Same(service, factory()); - } - - [Fact] - public void RegisterSingleton_RegistersLazy() - { - Setup.CreateContainer(); - Setup.Registry.RegisterSingleton(); - - var factory = Setup.Container.Resolve>(); - IServiceA service = null; - Assert.NotNull(factory); - var ex = Record.Exception(() => service = factory.Value); - Assert.Null(ex); - Assert.NotNull(service); - Assert.IsType(service); - Assert.Same(service, Setup.Container.Resolve>().Value); - } - -#if !UNITY - - [Fact] - public void RegisterSingleton_RegistersIEnumerable() - { - Setup.CreateContainer(); - Setup.Registry.Register(); - var services = Setup.Container.Resolve>(); - - Assert.NotNull(services); - Assert.Single(services); - Assert.IsType(services.First()); - } - -#endif - - [Fact] - public void RegisterInstance_RegistersSingletonService() - { - Setup.CreateContainer(); - var instance = new ServiceA(); - Setup.Registry.RegisterInstance(instance); - - var resolve1 = Setup.Container.Resolve(); - - Assert.IsType(resolve1); - Assert.Same(instance, resolve1); - } - - [Fact] - public void RegisterSingleton_LastInFirstOut() - { - Setup.CreateContainer(); - Setup.Registry.Register(); - Setup.Registry.RegisterSingleton(); - var service = Setup.Container.Resolve(); - - Assert.IsType(service); - Assert.Same(service, Setup.Container.Resolve()); - } - -#if !UNITY - [Theory] - [InlineData(0, typeof(ServiceA))] - [InlineData(1, typeof(CompositeService))] - public void RegisterSingleton_ResolveAll(int index, Type type) - { - Setup.CreateContainer(); - Setup.Registry.RegisterSingleton(); - Setup.Registry.RegisterSingleton(); - var services = Setup.Container.Resolve>(); - - Assert.NotNull(services); - Assert.Equal(2, services.Count()); - Assert.IsType(type, services.ElementAt(index)); - } - -#endif - - [Fact] - public void RegisterInstance_RegistersFunc() - { - Setup.CreateContainer(); - var instance = new ServiceA(); - Setup.Registry.RegisterInstance(instance); - - var factory = Setup.Container.Resolve>(); - IServiceA service = null; - Assert.NotNull(factory); - var ex = Record.Exception(() => service = factory()); - Assert.Null(ex); - Assert.NotNull(service); - Assert.IsType(service); - Assert.Same(service, factory()); - } - - [Fact] - public void RegisterInstance_RegistersLazy() - { - Setup.CreateContainer(); - var instance = new ServiceA(); - Setup.Registry.RegisterInstance(instance); - - var factory = Setup.Container.Resolve>(); - IServiceA service = null; - Assert.NotNull(factory); - var ex = Record.Exception(() => service = factory.Value); - Assert.Null(ex); - Assert.NotNull(service); - Assert.IsType(service); - Assert.Same(service, Setup.Container.Resolve>().Value); - } - - - -#if !UNITY - - [Fact] - public void RegisterInstance_RegistersIEnumerable() - { - Setup.CreateContainer(); - var instance = new ServiceA(); - Setup.Registry.RegisterInstance(instance); - var services = Setup.Container.Resolve>(); - - Assert.NotNull(services); - Assert.Single(services); - Assert.IsType(services.First()); - } - -#endif - - [Fact] - public void TryRegisterTransientDoesNotReplaceOriginalRegistration() - { - Setup.CreateContainer(); - Setup.Registry.TryRegister(); - Setup.Registry.TryRegister(); - - var service = Setup.Container.Resolve(); - Assert.IsType(service); - } - - [Fact] - public void TryRegisterScopedDoesNotReplaceOriginalRegistration() - { - Setup.CreateContainer(); - Setup.Registry.TryRegisterScoped(); - Setup.Registry.TryRegisterScoped(); - - var service = Setup.Container.Resolve(); - Assert.IsType(service); - } - - [Fact] - public void TryRegisterSingletonDoesNotReplaceOriginalRegistration() - { - Setup.CreateContainer(); - Setup.Registry.TryRegisterSingleton(); - Setup.Registry.TryRegisterSingleton(); - - var service = Setup.Container.Resolve(); - Assert.IsType(service); - } - } -} diff --git a/tests/Containers/Prism.Container.Shared/Tests/ContainerResolutionExceptionFixture.cs b/tests/Containers/Prism.Container.Shared/Tests/ContainerResolutionExceptionFixture.cs deleted file mode 100644 index 40ab39bb8c..0000000000 --- a/tests/Containers/Prism.Container.Shared/Tests/ContainerResolutionExceptionFixture.cs +++ /dev/null @@ -1,141 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using Prism.Ioc; -using Prism.Ioc.Mocks.Services; -using Prism.Ioc.Mocks.ViewModels; -using Prism.Ioc.Mocks.Views; -using Xunit; - -namespace Prism.Ioc.Tests -{ - public class ContainerResolutionExceptionFixture : TestBase - { - public ContainerResolutionExceptionFixture(ContainerSetup setup) - : base(setup) - { - } - - [Fact] - public void ThrowsContainerResolutionExceptionForUnregisteredService() - { - var container = Setup.CreateContainer(); - var ex = Record.Exception(() => container.Resolve()); - - Assert.NotNull(ex); - Assert.IsType(ex); - } - - [Fact] - public void ThrowsContainerResolutionExceptionForUnregisteredNamedPage() - { - var container = Setup.CreateContainer(); - var ex = Record.Exception(() => container.Resolve("missing")); - - Assert.NotNull(ex); - Assert.IsType(ex); - } - - [Fact] - public void GetErrorsDoesNotThrowException() - { - ContainerLocator.ResetContainer(); - var container = Setup.CreateContainer(); - ContainerLocator.SetContainerExtension(() => Setup.Extension); - Setup.Registry.Register("BadView"); - - var ex = Record.Exception(() => container.Resolve("BadView")); - - Assert.IsType(ex); - var cre = ex as ContainerResolutionException; - ContainerResolutionErrorCollection errors = null; - var ex2 = Record.Exception(() => errors = cre.GetErrors()); - Assert.Null(ex2); - } - - [Fact] - public void GetErrorsLocatesIssueWithBadView() - { - ContainerLocator.ResetContainer(); - var container = Setup.CreateContainer(); - ContainerLocator.SetContainerExtension(() => Setup.Extension); - Setup.Registry.Register("BadView"); - - var ex = Record.Exception(() => container.Resolve("BadView")); - - Assert.IsType(ex); - var cre = ex as ContainerResolutionException; - var errors = cre.GetErrors(); - - Assert.Contains(typeof(BadView), errors.Types); - } - - [Fact] - public void GetErrorsLocatesTargetInvocationException() - { - ContainerLocator.ResetContainer(); - var container = Setup.CreateContainer(); - ContainerLocator.SetContainerExtension(() => Setup.Extension); - Setup.Registry.Register("BadView"); - - var ex = Record.Exception(() => container.Resolve("BadView")); - - Assert.IsType(ex); - var cre = ex as ContainerResolutionException; - var errors = cre.GetErrors(); - - Assert.Contains(errors, x => x.Value is TargetInvocationException); - } - - [Fact] - public void GetErrorsLocatesXamlParseException() - { - ContainerLocator.ResetContainer(); - var container = Setup.CreateContainer(); - ContainerLocator.SetContainerExtension(() => Setup.Extension); - Setup.Registry.Register("BadView"); - - var ex = Record.Exception(() => container.Resolve("BadView")); - - Assert.IsType(ex); - var cre = ex as ContainerResolutionException; - var errors = cre.GetErrors(); - - Assert.Contains(errors, x => x.Value is XamlParseException); - } - - [Fact] - public void LocatesUnregisteredServiceType() - { - ContainerLocator.ResetContainer(); - var container = Setup.CreateContainer(); - ContainerLocator.SetContainerExtension(() => Setup.Extension); - - var ex = Record.Exception(() => container.Resolve()); - - Assert.IsType(ex); - var cre = ex as ContainerResolutionException; - var errors = cre.GetErrors(); - - Assert.Contains(typeof(IServiceA), errors.Types); - } - - [Fact] - public void LocatesUnregisteredServiceWithMissingRegistration() - { - ContainerLocator.ResetContainer(); - var container = Setup.CreateContainer(); - ContainerLocator.SetContainerExtension(() => Setup.Extension); - - var ex = Record.Exception(() => container.Resolve()); - - Assert.IsType(ex); - var cre = ex as ContainerResolutionException; - var errors = cre.GetErrors(); - - Assert.Contains(errors, x => x.Value is ContainerResolutionException innerCre && innerCre.ServiceType == typeof(IServiceA) && innerCre.Message == ContainerResolutionException.MissingRegistration); - } - } -} diff --git a/tests/Containers/Prism.Container.Shared/Tests/ContainerSetup.cs b/tests/Containers/Prism.Container.Shared/Tests/ContainerSetup.cs deleted file mode 100644 index 9aa7df061d..0000000000 --- a/tests/Containers/Prism.Container.Shared/Tests/ContainerSetup.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using Prism.Ioc; -using Prism.Mvvm; - -namespace Prism.Ioc.Tests -{ - public partial class ContainerSetup : IDisposable - { - public ContainerSetup() - { - ViewModelLocationProvider.SetDefaultViewModelFactory((view, type) => Container.Resolve(type)); - } - - public IContainerProvider Container => ContainerLocator.Container; - - public IContainerExtension Extension => ContainerLocator.Current; - - public IContainerRegistry Registry => Extension; - - public IContainerProvider CreateContainer() - { - ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => CreateContainerInternal()); - var container = ContainerLocator.Current; - container.CreateScope(); - return container; - } - - private bool _disposed; - - private void Dispose(bool disposing) - { - _disposed = true; - ContainerLocator.ResetContainer(); - } - - public void Dispose() - { - if (!_disposed) - { - Dispose(true); - GC.SuppressFinalize(this); - } - } - } -} diff --git a/tests/Containers/Prism.Container.Shared/Tests/TestBase.cs b/tests/Containers/Prism.Container.Shared/Tests/TestBase.cs deleted file mode 100644 index 8de104c102..0000000000 --- a/tests/Containers/Prism.Container.Shared/Tests/TestBase.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using Xunit; - -namespace Prism.Ioc.Tests -{ - [Collection(nameof(ContainerExtension))] - public abstract class TestBase : IClassFixture, IDisposable - { - private bool disposedValue; - - protected ContainerSetup Setup { get; } - - protected TestBase(ContainerSetup setup) - { - Setup = setup; - } - - protected virtual void Dispose(bool disposing) - { - if (!disposedValue) - { - if (disposing) - { - Setup.Dispose(); - } - - // TODO: free unmanaged resources (unmanaged objects) and override finalizer - // TODO: set large fields to null - disposedValue = true; - } - } - - public void Dispose() - { - Dispose(disposing: true); - GC.SuppressFinalize(this); - } - } -} diff --git a/tests/Containers/Prism.Container.Unity.Tests/ContainerHelpers.cs b/tests/Containers/Prism.Container.Unity.Tests/ContainerHelpers.cs deleted file mode 100644 index e9c3bab33d..0000000000 --- a/tests/Containers/Prism.Container.Unity.Tests/ContainerHelpers.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Unity; - -namespace Prism.Ioc.Tests -{ - public static class ContainerHelpers - { - public static IUnityContainer GetContainer(this IContainerExtension container) => - Prism.Unity.PrismIocExtensions.GetContainer((IContainerProvider)container); - } -} diff --git a/tests/Containers/Prism.Container.Unity.Tests/ContainerSetup.cs b/tests/Containers/Prism.Container.Unity.Tests/ContainerSetup.cs deleted file mode 100644 index db2bbbde96..0000000000 --- a/tests/Containers/Prism.Container.Unity.Tests/ContainerSetup.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using Prism.Ioc; -using Prism.Unity; -using Unity; - -namespace Prism.Ioc.Tests -{ - partial class ContainerSetup - { - IContainerExtension CreateContainerInternal() => new UnityContainerExtension(); - - public Type NativeContainerType => typeof(IUnityContainer); - } -} diff --git a/tests/Containers/Prism.Container.Unity.Tests/Prism.Ioc.Unity.Tests.csproj b/tests/Containers/Prism.Container.Unity.Tests/Prism.Ioc.Unity.Tests.csproj deleted file mode 100644 index 16a5f606ad..0000000000 --- a/tests/Containers/Prism.Container.Unity.Tests/Prism.Ioc.Unity.Tests.csproj +++ /dev/null @@ -1,38 +0,0 @@ - - - - net6.0 - false - $(DefineConstants);UNITY - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - all - runtime; build; native; contentfiles; analyzers - - - - - - - - - - - - diff --git a/tests/Forms/Prism.DI.Forms.Tests/Fixtures/PrismApplicationFixture.cs b/tests/Forms/Prism.DI.Forms.Tests/Fixtures/PrismApplicationFixture.cs index 2f2f1e0917..c2b20ef21d 100644 --- a/tests/Forms/Prism.DI.Forms.Tests/Fixtures/PrismApplicationFixture.cs +++ b/tests/Forms/Prism.DI.Forms.Tests/Fixtures/PrismApplicationFixture.cs @@ -222,7 +222,7 @@ public void CustomNamedNavigationService_Resolved_In_ViewModel() } [Fact] - public async Task XamlNavigation_NaviateTo() + public async Task XamlNavigation_NavigateTo() { var app = CreateMockApplication(); await app.NavigationService.NavigateAsync("NavigationPage/XamlViewMockA"); diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionFixture.cs b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionFixture.cs index 911d2a5ea2..66eb232de0 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionFixture.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionFixture.cs @@ -191,7 +191,7 @@ public void AddViewPassesSameScopeByDefaultToNamedView() } [Fact] - public void AddViewPassesDiferentScopeWhenAdding() + public void AddViewPassesDifferentScopeWhenAdding() { var regionManager = Mock.Of(); IRegion region = new Region @@ -491,7 +491,7 @@ public void NavigateDelegatesToIRegionNavigationService() var containerMock = new Mock(); containerMock.Setup(x => x.Resolve(typeof(IRegionNavigationService))).Returns(mockRegionNavigationService.Object); ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => containerMock.Object); + ContainerLocator.SetContainerExtension(containerMock.Object); // Act region.NavigationService.RequestNavigate(uri, navigationCallback, navigationParameters); diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionManagerFixture.cs b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionManagerFixture.cs index 692f839673..cb7194e54a 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionManagerFixture.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionManagerFixture.cs @@ -350,7 +350,7 @@ public void CanRegisterViewType() }; var containerMock = new Mock(); containerMock.Setup(c => c.Resolve(typeof(IRegionViewRegistry))).Returns(mockRegionContentRegistry); - ContainerLocator.SetContainerExtension(() => containerMock.Object); + ContainerLocator.SetContainerExtension(containerMock.Object); var regionManager = new RegionManager(); @@ -386,7 +386,7 @@ public void CanRegisterViewTypeGeneric() var containerMock = new Mock(); containerMock.Setup(c => c.Resolve(typeof(IRegionViewRegistry))).Returns(mockRegionContentRegistry); ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => containerMock.Object); + ContainerLocator.SetContainerExtension(containerMock.Object); var regionManager = new RegionManager(); diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionViewRegistryFixture.cs b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionViewRegistryFixture.cs index 694a97f80b..193fe56215 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionViewRegistryFixture.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionViewRegistryFixture.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading.Tasks; using Moq; using Prism.Ioc; @@ -16,7 +14,9 @@ public class RegionViewRegistryFixture [Fact] public void CanRegisterContentAndRetrieveIt() { + ContainerLocator.ResetContainer(); var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); containerMock.Setup(c => c.Resolve(typeof(MockContentObject))).Returns(new MockContentObject()); var registry = new RegionViewRegistry(containerMock.Object); @@ -52,6 +52,8 @@ public void ShouldRaiseEventWhenAddingContent() [Fact] public void CanRegisterContentAsDelegateAndRetrieveIt() { + ContainerLocator.ResetContainer(); + ContainerLocator.SetContainerExtension(Mock.Of()); var registry = new RegionViewRegistry(null); var content = new MockContentObject(); diff --git a/tests/Forms/Prism.Forms.Tests/Common/PageUtilitiesFixture.cs b/tests/Forms/Prism.Forms.Tests/Common/PageUtilitiesFixture.cs index 4187fec928..6b9cfa6683 100644 --- a/tests/Forms/Prism.Forms.Tests/Common/PageUtilitiesFixture.cs +++ b/tests/Forms/Prism.Forms.Tests/Common/PageUtilitiesFixture.cs @@ -36,7 +36,7 @@ public void DestroyContentPage() Assert.Equal(page, recorder.Records[0].Sender); Assert.Null(page.BindingContext); - Assert.Equal(0, page.Behaviors.Count); + Assert.Empty(page.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[0].Event); Assert.Equal(viewModel, recorder.Records[1].Sender); @@ -62,7 +62,7 @@ public void DestroyNavigationPage() // contentPage2 Assert.Equal(contentPage2, recorder.Records[0].Sender); Assert.Null(contentPage2.BindingContext); - Assert.Equal(0, contentPage2.Behaviors.Count); + Assert.Empty(contentPage2.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[0].Event); Assert.Equal(contentPage2ViewModel, recorder.Records[1].Sender); @@ -71,7 +71,7 @@ public void DestroyNavigationPage() // contentPage1 Assert.Equal(contentPage1, recorder.Records[2].Sender); Assert.Null(contentPage1.BindingContext); - Assert.Equal(0, contentPage1.Behaviors.Count); + Assert.Empty(contentPage1.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[2].Event); Assert.Equal(contentPage1ViewModel, recorder.Records[3].Sender); @@ -80,7 +80,7 @@ public void DestroyNavigationPage() // navigationPage Assert.Equal(navigationPage, recorder.Records[4].Sender); Assert.Null(navigationPage.BindingContext); - Assert.Equal(0, navigationPage.Behaviors.Count); + Assert.Empty(navigationPage.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[4].Event); Assert.Equal(navigationPageViewModel, recorder.Records[5].Sender); @@ -104,7 +104,7 @@ public void DestoryMasterDetailPage() var record = recorder.TakeFirst(); Assert.Equal(masterPage, record.Sender); Assert.Null(masterPage.BindingContext); - Assert.Equal(0, masterPage.Behaviors.Count); + Assert.Empty(masterPage.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, record.Event); record = recorder.TakeFirst(); @@ -115,7 +115,7 @@ record = recorder.TakeFirst(); record = recorder.TakeFirst(); Assert.Equal(detailPage, record.Sender); Assert.Null(detailPage.BindingContext); - Assert.Equal(0, detailPage.Behaviors.Count); + Assert.Empty(detailPage.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, record.Event); record = recorder.TakeFirst(); @@ -126,7 +126,7 @@ record = recorder.TakeFirst(); record = recorder.TakeFirst(); Assert.Equal(masterDetailPage, record.Sender); Assert.Null(masterDetailPage.BindingContext); - Assert.Equal(0, masterDetailPage.Behaviors.Count); + Assert.Empty(masterDetailPage.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, record.Event); record = recorder.TakeFirst(); @@ -167,7 +167,7 @@ public void DestroyTabbedPage() Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[0].Event); Assert.Equal(tab5, recorder.Records[1].Sender); - Assert.Equal(0, tab5.Behaviors.Count); + Assert.Empty(tab5.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[1].Event); Assert.Equal(tab5ChildViewModel, recorder.Records[2].Sender); @@ -175,14 +175,14 @@ public void DestroyTabbedPage() //tab 4 Assert.Equal(tab4Child, recorder.Records[3].Sender); - Assert.Equal(0, tab4Child.Behaviors.Count); + Assert.Empty(tab4Child.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[3].Event); Assert.Equal(tab4ChildViewModel, recorder.Records[4].Sender); Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[4].Event); Assert.Equal(tab4, recorder.Records[5].Sender); - Assert.Equal(0, tab4.Behaviors.Count); + Assert.Empty(tab4.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[5].Event); Assert.Equal(tab4ViewModel, recorder.Records[6].Sender); @@ -191,7 +191,7 @@ public void DestroyTabbedPage() //tab 3 Assert.Equal(tab3, recorder.Records[7].Sender); Assert.Null(tab3.BindingContext); - Assert.Equal(0, tab3.Behaviors.Count); + Assert.Empty(tab3.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[7].Event); Assert.Equal(tab3ViewModel, recorder.Records[8].Sender); @@ -202,7 +202,7 @@ public void DestroyTabbedPage() //tab 1 Assert.Equal(tab1, recorder.Records[9].Sender); Assert.Null(tab1.BindingContext); - Assert.Equal(0, tab1.Behaviors.Count); + Assert.Empty(tab1.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[9].Event); Assert.Equal(tab1ViewModel, recorder.Records[10].Sender); @@ -211,7 +211,7 @@ public void DestroyTabbedPage() //TabbedPage Assert.Equal(tabbedPage, recorder.Records[11].Sender); Assert.Null(tabbedPage.BindingContext); - Assert.Equal(0, tabbedPage.Behaviors.Count); + Assert.Empty(tabbedPage.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[11].Event); Assert.Equal(tabbedPageViewModel, recorder.Records[12].Sender); @@ -238,7 +238,7 @@ public void DestroyCarouselPage() // childPage2 Assert.Equal(childPage2, recorder.Records[1].Sender); Assert.Null(childPage2.BindingContext); - Assert.Equal(0, childPage2.Behaviors.Count); + Assert.Empty(childPage2.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[1].Event); Assert.Equal(childPage2ViewModel, recorder.Records[2].Sender); @@ -251,7 +251,7 @@ public void DestroyCarouselPage() // tabbedPage Assert.Equal(carouselPage, recorder.Records[4].Sender); Assert.Null(carouselPage.BindingContext); - Assert.Equal(0, carouselPage.Behaviors.Count); + Assert.Empty(carouselPage.Behaviors); Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[4].Event); Assert.Equal(carouselPageViewModel, recorder.Records[5].Sender); diff --git a/tests/Forms/Prism.Forms.Tests/Navigation/INavigationServiceExtensionsFixture.cs b/tests/Forms/Prism.Forms.Tests/Navigation/INavigationServiceExtensionsFixture.cs index 83a9986788..2a826764db 100644 --- a/tests/Forms/Prism.Forms.Tests/Navigation/INavigationServiceExtensionsFixture.cs +++ b/tests/Forms/Prism.Forms.Tests/Navigation/INavigationServiceExtensionsFixture.cs @@ -21,7 +21,7 @@ public INavigationServiceExtensionsFixture() ContainerLocator.ResetContainer(); var container = new Mock(); container.Setup(x => x.CreateScope()).Returns(Mock.Of()); - ContainerLocator.SetContainerExtension(() => container.Object); + ContainerLocator.SetContainerExtension(container.Object); PageNavigationRegistry.ClearRegistrationCache(); PageNavigationRegistry.Register("NavigationPage", typeof(NavigationPage)); @@ -51,7 +51,7 @@ public async Task GoBackToRootAsync_PopsToRoot() await navigationService.GoBackToRootAsync(); - Assert.Equal(1, rootPage.Navigation.NavigationStack.Count); + Assert.Single(rootPage.Navigation.NavigationStack); Assert.Equal(page1, rootPage.Navigation.NavigationStack[0]); } @@ -83,7 +83,7 @@ private async Task GoBackToRootAsync_PopsToRoot_INavigationAware_Destroy() await navigationService.GoBackToRootAsync(); - Assert.Equal(1, rootPage.Navigation.NavigationStack.Count); + Assert.Single(rootPage.Navigation.NavigationStack); Assert.Equal(page1, rootPage.Navigation.NavigationStack[0]); Assert.Equal(14, recorder.Records.Count); diff --git a/tests/Forms/Prism.Forms.Tests/Navigation/PageNavigationServiceFixture.cs b/tests/Forms/Prism.Forms.Tests/Navigation/PageNavigationServiceFixture.cs index c0e41745cd..614daa218d 100644 --- a/tests/Forms/Prism.Forms.Tests/Navigation/PageNavigationServiceFixture.cs +++ b/tests/Forms/Prism.Forms.Tests/Navigation/PageNavigationServiceFixture.cs @@ -26,7 +26,7 @@ public PageNavigationServiceFixture() ContainerLocator.ResetContainer(); _container = new PageNavigationContainerMock(); - ContainerLocator.SetContainerExtension(() => _container); + ContainerLocator.SetContainerExtension(_container); _container.Register("PageMock", typeof(PageMock)); @@ -575,8 +575,8 @@ public async Task Navigate_FromNavigationPage_WithoutChildPage_ToContentPage() ((IPageAware)navigationService).Page = navigationPage; await navigationService.NavigateAsync("ContentPage"); - Assert.Equal(0, navigationPage.Navigation.ModalStack.Count); - Assert.Equal(1, navigationPage.Navigation.NavigationStack.Count); + Assert.Empty(navigationPage.Navigation.ModalStack); + Assert.Single(navigationPage.Navigation.NavigationStack); var contentPage = navigationPage.Navigation.NavigationStack.Last(); Assert.IsType(contentPage); @@ -627,7 +627,7 @@ public async Task NavigateAsync_From_ChildPageOfNavigationPage() ((IPageAware)navigationService).Page = contentPageMock; await navigationService.NavigateAsync("SecondContentPageMock"); - Assert.Equal(0, navigationPage.Navigation.ModalStack.Count); + Assert.Empty(navigationPage.Navigation.ModalStack); Assert.Equal(2, navigationPage.Navigation.NavigationStack.Count); var pageMock = navigationPage.Navigation.NavigationStack.Last(); @@ -691,8 +691,8 @@ public async Task NavigateAsync_From_NavigationPage_With_ChildPage_And_DoesNotRe ((IPageAware)navigationService).Page = navigationPage; await navigationService.NavigateAsync("ContentPage"); - Assert.Equal(0, navigationPage.Navigation.ModalStack.Count); - Assert.Equal(1, navigationPage.Navigation.NavigationStack.Count); + Assert.Empty(navigationPage.Navigation.ModalStack); + Assert.Single(navigationPage.Navigation.NavigationStack); var rootPage = navigationPage.Navigation.NavigationStack.Last(); Assert.Equal(contentPageMock, rootPage); @@ -884,7 +884,7 @@ public async Task NavigateAsync_From_NavigationPage_When_NotClearNavigationStack ((IPageAware)navigationService).Page = navigationPage; await navigationService.NavigateAsync("SecondContentPageMock"); - Assert.Equal(0, navigationPage.Navigation.ModalStack.Count); + Assert.Empty(navigationPage.Navigation.ModalStack); Assert.Equal(2, navigationPage.Navigation.NavigationStack.Count); var currentPage = navigationPage.Navigation.NavigationStack.Last(); @@ -994,7 +994,7 @@ public async Task DeepNavigate_From_ContentPage_To_NavigationPage_ToContentPage_ await navigationService.NavigateAsync("/NavigationPage/ContentPage"); - Assert.Equal(0, rootPage.Navigation.ModalStack.Count); + Assert.Empty(rootPage.Navigation.ModalStack); var navPage = _applicationProvider.MainPage; Assert.IsType(navPage); @@ -1010,7 +1010,7 @@ public async Task DeepNavigate_From_ContentPage_To_NavigationPage_ToContentPage_ await navigationService.NavigateAsync(new Uri("http://localhost/NavigationPage/ContentPage", UriKind.Absolute)); - Assert.Equal(0, rootPage.Navigation.ModalStack.Count); + Assert.Empty(rootPage.Navigation.ModalStack); var navPage = _applicationProvider.MainPage; Assert.IsType(navPage); @@ -1106,7 +1106,7 @@ public async Task DeepNavigate_From_ContentPage_To_NavigationPageWithDifferentNa await navigationService.NavigateAsync("ContentPage/NavigationPageWithStackNoMatch/ContentPage"); var navPage = rootPage.Navigation.ModalStack[0].Navigation.ModalStack[0]; - Assert.Equal(1, navPage.Navigation.NavigationStack.Count); + Assert.Single(navPage.Navigation.NavigationStack); } [Fact] @@ -1197,8 +1197,8 @@ public async Task DeepNavigate_ToEmptyMasterDetailPage_ToContentPage() await navigationService.NavigateAsync("MasterDetailPage-Empty/ContentPage"); - Assert.Equal(1, rootPage.Navigation.ModalStack.Count); - Assert.Equal(0, rootPage.Navigation.NavigationStack.Count); + Assert.Single(rootPage.Navigation.ModalStack); + Assert.Empty(rootPage.Navigation.NavigationStack); var masterDetail = rootPage.Navigation.ModalStack[0] as MasterDetailPageEmptyMock; Assert.NotNull(masterDetail); @@ -1216,8 +1216,8 @@ public async Task DeepNavigate_ToEmptyMasterDetailPage_ToContentPage_UseModalNav //await navigationService.NavigateAsync("MasterDetailPage-Empty/ContentPage", useModalNavigation: true); await navigationService.NavigateAsync("MasterDetailPage-Empty/ContentPage"); - Assert.Equal(1, rootPage.Navigation.ModalStack.Count); - Assert.Equal(0, rootPage.Navigation.NavigationStack.Count); + Assert.Single(rootPage.Navigation.ModalStack); + Assert.Empty(rootPage.Navigation.NavigationStack); var masterDetail = rootPage.Navigation.ModalStack[0] as MasterDetailPageEmptyMock; Assert.NotNull(masterDetail); Assert.NotNull(masterDetail.Detail); @@ -1232,12 +1232,12 @@ public async Task DeepNavigate_ToEmptyMasterDetailPage_ToContentPage_NotUseModal var navigationPage = new NavigationPage(rootPage); ((IPageAware)navigationService).Page = rootPage; - Assert.Equal(1, rootPage.Navigation.NavigationStack.Count); + Assert.Single(rootPage.Navigation.NavigationStack); Assert.IsType(navigationPage.CurrentPage); await navigationService.NavigateAsync("MasterDetailPage-Empty/ContentPage"); - Assert.Equal(0, rootPage.Navigation.ModalStack.Count); + Assert.Empty(rootPage.Navigation.ModalStack); Assert.Equal(2, rootPage.Navigation.NavigationStack.Count); var masterDetail = rootPage.Navigation.NavigationStack[1] as MasterDetailPageEmptyMock; Assert.NotNull(masterDetail); @@ -1272,10 +1272,10 @@ public async Task DeepNavigate_ToEmptyMasterDetailPage_ToEmptyNavigationPage_ToC Assert.NotNull(masterDetail); Assert.NotNull(masterDetail.Detail); Assert.IsType(masterDetail.Detail); - Assert.Equal(0, masterDetail.Navigation.ModalStack.Count); - Assert.Equal(0, masterDetail.Navigation.NavigationStack.Count); - Assert.Equal(0, masterDetail.Detail.Navigation.ModalStack.Count); - Assert.Equal(1, masterDetail.Detail.Navigation.NavigationStack.Count); + Assert.Empty(masterDetail.Navigation.ModalStack); + Assert.Empty(masterDetail.Navigation.NavigationStack); + Assert.Empty(masterDetail.Detail.Navigation.ModalStack); + Assert.Single(masterDetail.Detail.Navigation.NavigationStack); Assert.IsType(masterDetail.Detail.Navigation.NavigationStack.Last()); } @@ -1291,10 +1291,10 @@ public async Task DeepNavigate_ToEmptyMasterDetailPage_ToNavigationPage_ToConten Assert.NotNull(masterDetail); Assert.NotNull(masterDetail.Detail); Assert.IsType(masterDetail.Detail); - Assert.Equal(0, masterDetail.Navigation.ModalStack.Count); - Assert.Equal(0, masterDetail.Navigation.NavigationStack.Count); - Assert.Equal(0, masterDetail.Detail.Navigation.ModalStack.Count); - Assert.Equal(1, masterDetail.Detail.Navigation.NavigationStack.Count); + Assert.Empty(masterDetail.Navigation.ModalStack); + Assert.Empty(masterDetail.Navigation.NavigationStack); + Assert.Empty(masterDetail.Detail.Navigation.ModalStack); + Assert.Single(masterDetail.Detail.Navigation.NavigationStack); Assert.IsType(masterDetail.Detail.Navigation.NavigationStack.Last()); } @@ -1948,7 +1948,7 @@ public async Task RemoveAndNavigate_FourLevels() await navigationService.NavigateAsync("../../../../PageMock"); - Assert.Equal(1, rootPage.Navigation.NavigationStack.Count); + Assert.Single(rootPage.Navigation.NavigationStack); Assert.IsType(rootPage.Navigation.NavigationStack[0]); } @@ -2018,7 +2018,7 @@ public async Task RemoveAndGoBack_ThreeLevels() await navigationService.NavigateAsync("../../../"); - Assert.Equal(1, rootPage.Navigation.NavigationStack.Count); + Assert.Single(rootPage.Navigation.NavigationStack); Assert.IsType(rootPage.Navigation.NavigationStack.Last()); } diff --git a/tests/Forms/Prism.Forms.Tests/Services/DialogServiceTests.cs b/tests/Forms/Prism.Forms.Tests/Services/DialogServiceTests.cs index 1709c873c2..38fb3db96c 100644 --- a/tests/Forms/Prism.Forms.Tests/Services/DialogServiceTests.cs +++ b/tests/Forms/Prism.Forms.Tests/Services/DialogServiceTests.cs @@ -142,7 +142,7 @@ public void UseMaskFalseProhibitsMaskInsertion() Assert.NotNull(dialogPage); var layout = dialogPage.Content as AbsoluteLayout; - Assert.Equal(1, layout.Children.Count); + Assert.Single(layout.Children); } [Fact] diff --git a/tests/Prism.Core.Tests/Ioc/ContainerLocatorFixture.cs b/tests/Prism.Core.Tests/Ioc/ContainerLocatorFixture.cs deleted file mode 100644 index fbea2bba51..0000000000 --- a/tests/Prism.Core.Tests/Ioc/ContainerLocatorFixture.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Moq; -using Prism.Ioc; -using Xunit; - -namespace Prism.Tests.Ioc -{ - public class ContainerLocator { } - - [CollectionDefinition(nameof(ContainerLocator), DisableParallelization = true)] - public class ContainerLocatorCollection : ICollectionFixture - { - } - - [Collection(nameof(ContainerLocator))] - public class ContainerLocatorFixture - { - [Fact] - public void FactoryCreatesContainerExtension() - { - Prism.Ioc.ContainerLocator.ResetContainer(); - Assert.Null(Prism.Ioc.ContainerLocator.Current); - Prism.Ioc.ContainerLocator.SetContainerExtension(() => new Mock().Object); - Assert.NotNull(Prism.Ioc.ContainerLocator.Current); - } - - [Fact] - public void ResetNullsCurrentContainer() - { - Prism.Ioc.ContainerLocator.ResetContainer(); - Assert.Null(Prism.Ioc.ContainerLocator.Current); - Prism.Ioc.ContainerLocator.SetContainerExtension(() => new Mock().Object); - Assert.NotNull(Prism.Ioc.ContainerLocator.Current); - Prism.Ioc.ContainerLocator.ResetContainer(); - Assert.Null(Prism.Ioc.ContainerLocator.Current); - } - - [Fact] - public void FactoryOnlySetsContainerOnce() - { - Prism.Ioc.ContainerLocator.ResetContainer(); - var container = new Mock().Object; - var container2 = new Mock().Object; - - Prism.Ioc.ContainerLocator.SetContainerExtension(() => container); - Assert.Same(container, Prism.Ioc.ContainerLocator.Container); - - Prism.Ioc.ContainerLocator.SetContainerExtension(() => container2); - Assert.NotSame(container2, Prism.Ioc.ContainerLocator.Container); - Assert.Same(container, Prism.Ioc.ContainerLocator.Container); - } - } -} diff --git a/tests/Prism.Core.Tests/Ioc/ContainerRegistryExtensionsFixture.cs b/tests/Prism.Core.Tests/Ioc/ContainerRegistryExtensionsFixture.cs deleted file mode 100644 index eb91ab7aca..0000000000 --- a/tests/Prism.Core.Tests/Ioc/ContainerRegistryExtensionsFixture.cs +++ /dev/null @@ -1,282 +0,0 @@ -using System; -using Moq; -using Prism.Ioc; -using Xunit; - -namespace Prism.Tests.Ioc -{ - public class ContainerRegistryExtensionsFixture - { - private interface ITestService { } - - private interface ITest2Service { } - - private class TestService : ITestService, ITest2Service { } - - [Fact] - public void RegisterInstanceOfT() - { - var testService = new TestService(); - var mock = new Mock(); - mock.Setup(x => x.RegisterInstance(typeof(TestService), testService)) - .Returns(mock.Object); - - var cr = mock.Object.RegisterInstance(testService); - Assert.Same(mock.Object, cr); - - mock.Verify(x => x.RegisterInstance(typeof(TestService), testService)); - } - - [Fact] - public void RegisterNamedInstanceOfT() - { - var testService = new TestService(); - var mock = new Mock(); - mock.Setup(x => x.RegisterInstance(typeof(TestService), testService, "Test")) - .Returns(mock.Object); - - var cr = mock.Object.RegisterInstance(testService, "Test"); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.RegisterInstance(typeof(TestService), testService, "Test")); - } - - [Fact] - public void RegisterSingletonFromConcreteType() - { - var mock = new Mock(); - mock.Setup(x => x.RegisterSingleton(typeof(TestService), typeof(TestService))) - .Returns(mock.Object); - - var cr = mock.Object.RegisterSingleton(typeof(TestService)); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.RegisterSingleton(typeof(TestService), typeof(TestService))); - } - - [Fact] - public void RegisterSingletonFromGenericConcreteType() - { - var mock = new Mock(); - mock.Setup(x => x.RegisterSingleton(typeof(TestService), typeof(TestService))) - .Returns(mock.Object); - - var cr = mock.Object.RegisterSingleton(); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.RegisterSingleton(typeof(TestService), typeof(TestService))); - } - - [Fact] - public void RegisterSingletonWithService() - { - var mock = new Mock(); - mock.Setup(x => x.RegisterSingleton(typeof(ITestService), typeof(TestService))) - .Returns(mock.Object); - - var cr = mock.Object.RegisterSingleton(); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.RegisterSingleton(typeof(ITestService), typeof(TestService))); - } - - [Fact] - public void RegisterSingletonNamedWithService() - { - - var mock = new Mock(); - mock.Setup(x => x.RegisterSingleton(typeof(ITestService), typeof(TestService), "Test")) - .Returns(mock.Object); - - var cr = mock.Object.RegisterSingleton("Test"); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.RegisterSingleton(typeof(ITestService), typeof(TestService), "Test")); - } - - [Fact] - public void RegisterSingletonFromDelegateFunction() - { - var mock = new Mock(); - mock.Setup(x => x.RegisterSingleton(typeof(ITestService), TestDelegate)) - .Returns(mock.Object); - - var cr = mock.Object.RegisterSingleton(TestDelegate); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.RegisterSingleton(typeof(ITestService), TestDelegate)); - } - - [Fact] - public void RegisterSingletonFromDelegateFunctionWithContainerProvider() - { - var mock = new Mock(); - mock.Setup(x => x.RegisterSingleton(typeof(ITestService), TestDelegate)) - .Returns(mock.Object); - - var cr = mock.Object.RegisterSingleton(TestDelegate); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.RegisterSingleton(typeof(ITestService), TestDelegate)); - } - - [Fact] - public void RegisterSingletonWithManyInterfaces() - { - var mock = new Mock(); - mock.Setup(x => x.RegisterManySingleton(It.IsAny(), It.IsAny())) - .Returns(mock.Object); - var services = new[] { typeof(ITestService), typeof(ITest2Service) }; - var cr = mock.Object.RegisterManySingleton(services); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.RegisterManySingleton(typeof(TestService), services)); - } - - [Fact] - public void RegisterFromConcreteType() - { - var mock = new Mock(); - mock.Setup(x => x.Register(typeof(TestService), typeof(TestService))) - .Returns(mock.Object); - - var cr = mock.Object.Register(typeof(TestService)); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.Register(typeof(TestService), typeof(TestService))); - } - - [Fact] - public void RegisterFromGenericConcreteType() - { - var mock = new Mock(); - mock.Setup(x => x.Register(typeof(TestService), typeof(TestService))) - .Returns(mock.Object); - - var cr = mock.Object.Register(); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.Register(typeof(TestService), typeof(TestService))); - } - - [Fact] - public void RegisterWithService() - { - var mock = new Mock(); - mock.Setup(x => x.Register(typeof(ITestService), typeof(TestService))) - .Returns(mock.Object); - - var cr = mock.Object.Register(); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.Register(typeof(ITestService), typeof(TestService))); - } - - [Fact] - public void RegisterNamedWithService() - { - - var mock = new Mock(); - mock.Setup(x => x.Register(typeof(ITestService), typeof(TestService), "Test")) - .Returns(mock.Object); - - var cr = mock.Object.Register("Test"); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.Register(typeof(ITestService), typeof(TestService), "Test")); - } - - [Fact] - public void RegisterFromDelegateFunction() - { - var mock = new Mock(); - mock.Setup(x => x.Register(typeof(ITestService), TestDelegate)) - .Returns(mock.Object); - - var cr = mock.Object.Register(TestDelegate); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.Register(typeof(ITestService), TestDelegate)); - } - - [Fact] - public void RegisterFromDelegateFunctionWithContainerProvider() - { - var mock = new Mock(); - mock.Setup(x => x.Register(typeof(ITestService), TestDelegate)) - .Returns(mock.Object); - - var cr = mock.Object.Register(TestDelegate); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.Register(typeof(ITestService), TestDelegate)); - } - - [Fact] - public void RegisterWithManyInterfaces() - { - var mock = new Mock(); - mock.Setup(x => x.RegisterMany(It.IsAny(), It.IsAny())) - .Returns(mock.Object); - var services = new[] { typeof(ITestService), typeof(ITest2Service) }; - var cr = mock.Object.RegisterMany(services); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.RegisterMany(typeof(TestService), services)); - } - - [Fact] - public void RegisterScopedFromConcreteType() - { - var mock = new Mock(); - mock.Setup(x => x.RegisterScoped(typeof(TestService), typeof(TestService))) - .Returns(mock.Object); - - var cr = mock.Object.RegisterScoped(typeof(TestService)); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.RegisterScoped(typeof(TestService), typeof(TestService))); - } - - [Fact] - public void RegisterScopedFromGenericConcreteType() - { - var mock = new Mock(); - mock.Setup(x => x.RegisterScoped(typeof(TestService), typeof(TestService))) - .Returns(mock.Object); - - var cr = mock.Object.RegisterScoped(); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.RegisterScoped(typeof(TestService), typeof(TestService))); - } - - [Fact] - public void RegisterScopedWithService() - { - var mock = new Mock(); - mock.Setup(x => x.RegisterScoped(typeof(ITestService), typeof(TestService))) - .Returns(mock.Object); - - var cr = mock.Object.RegisterScoped(); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.RegisterScoped(typeof(ITestService), typeof(TestService))); - } - - [Fact] - public void RegisterScopedFromDelegateFunction() - { - var mock = new Mock(); - mock.Setup(x => x.RegisterScoped(typeof(ITestService), TestDelegate)) - .Returns(mock.Object); - - var cr = mock.Object.RegisterScoped(TestDelegate); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.RegisterScoped(typeof(ITestService), TestDelegate)); - } - - [Fact] - public void RegisterScopedFromDelegateFunctionWithContainerProvider() - { - var mock = new Mock(); - mock.Setup(x => x.RegisterScoped(typeof(ITestService), TestDelegate)) - .Returns(mock.Object); - - var cr = mock.Object.RegisterScoped(TestDelegate); - Assert.Same(mock.Object, cr); - mock.Verify(x => x.RegisterScoped(typeof(ITestService), TestDelegate)); - } - - - - - private static ITestService TestDelegate() => - new TestService(); - - private static ITestService TestDelegateFactory(IContainerProvider containerProvider) => - containerProvider.Resolve("Named"); - } -} diff --git a/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Bootstrapper/BootstrapperRunMethodFixture.cs b/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Bootstrapper/BootstrapperRunMethodFixture.cs index 746de5da37..59cb362a46 100644 --- a/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Bootstrapper/BootstrapperRunMethodFixture.cs +++ b/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Bootstrapper/BootstrapperRunMethodFixture.cs @@ -154,7 +154,7 @@ public void RunShouldCallRegisterTypes() public void SetsContainerLocatorCurrentContainer() { ContainerLocator.ResetContainer(); - Assert.Null(ContainerLocator.Container); + Assert.False(ContainerLocator.IsInitialized); var bootstrapper = new MockBootstrapper(); bootstrapper.Run(); diff --git a/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Ioc/ContainerProviderExtensionFixture.cs b/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Ioc/ContainerProviderExtensionFixture.cs index fd0fb7abb3..57a35cb5ab 100644 --- a/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Ioc/ContainerProviderExtensionFixture.cs +++ b/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Ioc/ContainerProviderExtensionFixture.cs @@ -42,7 +42,7 @@ static ContainerProviderExtensionFixture() public ContainerProviderExtensionFixture() { ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => _containerExtension); + ContainerLocator.SetContainerExtension(_containerExtension); } public void Dispose() diff --git a/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Regions/RegionNavigationContentLoaderFixture.cs b/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Regions/RegionNavigationContentLoaderFixture.cs index c73f875ed8..2a49859e23 100644 --- a/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Regions/RegionNavigationContentLoaderFixture.cs +++ b/tests/Wpf/Prism.Container.Wpf.Shared/Fixtures/Regions/RegionNavigationContentLoaderFixture.cs @@ -20,7 +20,7 @@ public RegionNavigationContentLoaderFixture() _container.Register(typeof(IRegionNavigationContentLoader), typeof(RegionNavigationContentLoader)); _container.Register(); ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => _container); + ContainerLocator.SetContainerExtension(_container); } [StaFact] diff --git a/tests/Wpf/Prism.DryIoc.Wpf.Tests/ContainerHelper.cs b/tests/Wpf/Prism.DryIoc.Wpf.Tests/ContainerHelper.cs index 78bab56911..3f10710a45 100644 --- a/tests/Wpf/Prism.DryIoc.Wpf.Tests/ContainerHelper.cs +++ b/tests/Wpf/Prism.DryIoc.Wpf.Tests/ContainerHelper.cs @@ -1,6 +1,6 @@ using System; using DryIoc; -using Prism.DryIoc; +using Prism.Container.DryIoc; using Prism.Ioc; namespace Prism.Container.Wpf.Tests diff --git a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Fixtures/BootstrapperRunMethodFixture.cs b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Fixtures/BootstrapperRunMethodFixture.cs index 87b88c73e2..557d52b1c3 100644 --- a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Fixtures/BootstrapperRunMethodFixture.cs +++ b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Fixtures/BootstrapperRunMethodFixture.cs @@ -1,6 +1,7 @@ using System; using DryIoc; using Moq; +using Prism.Container.DryIoc; using Prism.Container.Wpf.Mocks; using Prism.DryIoc; using Prism.Events; diff --git a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Fixtures/ContainerLocatorFixture.cs b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Fixtures/ContainerLocatorFixture.cs deleted file mode 100644 index 02d887ccc9..0000000000 --- a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Fixtures/ContainerLocatorFixture.cs +++ /dev/null @@ -1,27 +0,0 @@ -using DryIoc; -using Moq; -using Prism.Ioc; -using Xunit; - -namespace Prism.DryIoc.Wpf.Tests -{ - public class ContainerLocatorFixture - { - [Fact] - public void ShouldForwardResolveToInnerContainer() - { - var mockContainer = new Mock(); - - Assert.Empty(mockContainer.Invocations); - var containerExtension = new DryIocContainerExtension(mockContainer.Object); - - // We register the IContainerExtension and IContainerProvider directly with the container in the ctor. - Assert.Equal(2, mockContainer.Invocations.Count); - ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => containerExtension); - - var resolved = ContainerLocator.Container.Resolve(typeof(object)); - Assert.Equal(3, mockContainer.Invocations.Count); - } - } -} diff --git a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockBootstrapper.cs b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockBootstrapper.cs index 6ee2c090f0..959ad84ce0 100644 --- a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockBootstrapper.cs +++ b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockBootstrapper.cs @@ -3,6 +3,7 @@ using System.Windows; using System.Windows.Controls; using DryIoc; +using Prism.Container.DryIoc; using Prism.DryIoc; using Prism.Ioc; using Prism.Modularity; diff --git a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs index 2c0ffb6855..b284081762 100644 --- a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs +++ b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs @@ -1,6 +1,7 @@ using System.Windows; using System.Windows.Controls; using DryIoc; +using Prism.Container.DryIoc; using Prism.DryIoc; using Prism.Ioc; diff --git a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Prism.DryIoc.Wpf.Tests.csproj b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Prism.DryIoc.Wpf.Tests.csproj index 282d473e5b..da17ee6127 100644 --- a/tests/Wpf/Prism.DryIoc.Wpf.Tests/Prism.DryIoc.Wpf.Tests.csproj +++ b/tests/Wpf/Prism.DryIoc.Wpf.Tests/Prism.DryIoc.Wpf.Tests.csproj @@ -11,7 +11,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/Wpf/Prism.Unity.Wpf.Tests/ContainerHelper.cs b/tests/Wpf/Prism.Unity.Wpf.Tests/ContainerHelper.cs index fb8778baf3..7cfe542dd1 100644 --- a/tests/Wpf/Prism.Unity.Wpf.Tests/ContainerHelper.cs +++ b/tests/Wpf/Prism.Unity.Wpf.Tests/ContainerHelper.cs @@ -1,6 +1,6 @@ using System; +using Prism.Container.Unity; using Prism.Ioc; -using Prism.Unity; using Unity; namespace Prism.Container.Wpf.Tests diff --git a/tests/Wpf/Prism.Unity.Wpf.Tests/Fixtures/BootstrapperRunMethodFixture.cs b/tests/Wpf/Prism.Unity.Wpf.Tests/Fixtures/BootstrapperRunMethodFixture.cs index 537318ea29..5a68a38485 100644 --- a/tests/Wpf/Prism.Unity.Wpf.Tests/Fixtures/BootstrapperRunMethodFixture.cs +++ b/tests/Wpf/Prism.Unity.Wpf.Tests/Fixtures/BootstrapperRunMethodFixture.cs @@ -1,11 +1,11 @@ using System; using Moq; +using Prism.Container.Unity; using Prism.Container.Wpf.Mocks; using Prism.Events; using Prism.Ioc; using Prism.Modularity; using Prism.Navigation.Regions; -using Prism.Unity; using Unity; using Unity.Lifetime; using Xunit; diff --git a/tests/Wpf/Prism.Unity.Wpf.Tests/Fixtures/ContainerLocatorFixture.cs b/tests/Wpf/Prism.Unity.Wpf.Tests/Fixtures/ContainerLocatorFixture.cs deleted file mode 100644 index 28b03f692f..0000000000 --- a/tests/Wpf/Prism.Unity.Wpf.Tests/Fixtures/ContainerLocatorFixture.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using Moq; -using Prism.Ioc; -using Unity; -using Unity.Lifetime; -using Unity.Resolution; -using Xunit; - -namespace Prism.Unity.Wpf.Tests -{ - public class ContainerLocatorFixture - { - [Fact] - public void ShouldForwardResolveToInnerContainer() - { - object myInstance = new object(); - - var mockContainer = new Mock(); - mockContainer.Setup(c => c.Resolve(typeof(object), null, It.IsAny())).Returns(myInstance); - var containerExtension = new UnityContainerExtension(mockContainer.Object); - ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => containerExtension); - var resolved = ContainerLocator.Container.Resolve(typeof(object)); - mockContainer.Verify(c => c.Resolve(typeof(object), null, It.IsAny()), Times.Once); - Assert.Same(myInstance, resolved); - } - } -} diff --git a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockBootstrapper.cs b/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockBootstrapper.cs index 001dc456bb..df7b3c49c7 100644 --- a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockBootstrapper.cs +++ b/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockBootstrapper.cs @@ -2,6 +2,7 @@ using System.Reflection; using System.Windows; using System.Windows.Controls; +using Prism.Container.Unity; using Prism.Ioc; using Prism.Modularity; using Prism.Navigation.Regions; diff --git a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs b/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs index e14ad5a3eb..ee7d091aca 100644 --- a/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs +++ b/tests/Wpf/Prism.Unity.Wpf.Tests/Mocks/MockedContainerBootstrapper.cs @@ -1,5 +1,6 @@ using System.Windows; using System.Windows.Controls; +using Prism.Container.Unity; using Prism.Ioc; using Prism.Unity; using Unity; diff --git a/tests/Wpf/Prism.Wpf.Tests/ExceptionExtensionsFixture.cs b/tests/Wpf/Prism.Wpf.Tests/ExceptionExtensionsFixture.cs deleted file mode 100644 index 9877963011..0000000000 --- a/tests/Wpf/Prism.Wpf.Tests/ExceptionExtensionsFixture.cs +++ /dev/null @@ -1,157 +0,0 @@ - - -using System; -using Xunit; - -namespace Prism.Wpf.Tests -{ - - public class ExceptionExtensionsFixture - { - [Fact] - // Note, this test cannot be run twice in the same test run, because the registeration is static - // and we're not supplying an 'Unregister' method - public void CanRegisterFrameworkExceptionTypes() - { - Assert.False(ExceptionExtensions.IsFrameworkExceptionRegistered(typeof(MockException))); - - ExceptionExtensions.RegisterFrameworkExceptionType(typeof(MockException)); - - Assert.True(ExceptionExtensions.IsFrameworkExceptionRegistered(typeof(MockException))); - } - - [Fact] - public void CanGetRootException() - { - Exception caughtException = null; - ExceptionExtensions.RegisterFrameworkExceptionType(typeof(FrameworkException1)); - try - { - try - { - throw new RootException(); - } - catch (Exception ex) - { - - throw new FrameworkException1(ex); - } - } - catch (Exception ex) - { - caughtException = ex; - } - - Assert.NotNull(caughtException); - - Exception exception = caughtException.GetRootException(); - - Assert.IsType(exception); - } - - [Fact] - public void CanCompensateForInnerFrameworkExceptionType() - { - Exception caughtException = null; - ExceptionExtensions.RegisterFrameworkExceptionType(typeof(FrameworkException2)); - try - { - try - { - try - { - throw new RootException(); - } - catch (Exception ex) - { - - throw new FrameworkException2(ex); - } - } - catch (Exception ex) - { - - throw new NonFrameworkException(ex); - } - } - catch (Exception ex) - { - caughtException = ex; - } - - Assert.NotNull(caughtException); - - Exception exception = caughtException.GetRootException(); - Assert.IsType(exception); - } - - [Fact] - public void GetRootExceptionReturnsTopExceptionWhenNoUserExceptionFound() - { - Exception caughtException = null; - ExceptionExtensions.RegisterFrameworkExceptionType(typeof(FrameworkException1)); - ExceptionExtensions.RegisterFrameworkExceptionType(typeof(FrameworkException2)); - try - { - try - { - throw new FrameworkException1(null); - } - catch (Exception ex) - { - - throw new FrameworkException2(ex); - } - } - catch (Exception ex) - { - caughtException = ex; - } - - Assert.NotNull(caughtException); - - Exception exception = caughtException.GetRootException(); - Assert.IsType(exception); - } - - private class MockException : Exception - { - - } - - - - private class FrameworkException2 : Exception - { - public FrameworkException2(Exception innerException) - : base("", innerException) - { - - } - } - - private class FrameworkException1 : Exception - { - public FrameworkException1(Exception innerException) : base("", innerException) - { - - } - } - - private class RootException : Exception - { } - - private class NonFrameworkException : Exception - { - public NonFrameworkException(Exception innerException) - : base("", innerException) - { - - } - } - - } - - - -} diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/AllActiveRegionFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/AllActiveRegionFixture.cs index f9260d5350..526174dc60 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/AllActiveRegionFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/AllActiveRegionFixture.cs @@ -1,17 +1,17 @@ - - using System; +using Moq; +using Prism.Ioc; using Prism.Navigation.Regions; using Xunit; namespace Prism.Wpf.Tests.Regions { - public class AllActiveRegionFixture { [Fact] public void AddingViewsToRegionMarksThemAsActive() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new AllActiveRegion(); var view = new object(); @@ -31,9 +31,6 @@ public void DeactivateThrows() region.Deactivate(view); }); - } - - } } diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/AutoPopulateRegionBehaviorFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/AutoPopulateRegionBehaviorFixture.cs index 321dea66cb..4b8b3784d4 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/AutoPopulateRegionBehaviorFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/AutoPopulateRegionBehaviorFixture.cs @@ -1,7 +1,6 @@ - - using System; using System.Collections.Generic; +using Moq; using Prism.Ioc; using Prism.Navigation.Regions; using Prism.Navigation.Regions.Behaviors; @@ -16,6 +15,7 @@ public class AutoPopulateRegionBehaviorFixture [Fact] public void ShouldGetViewsFromRegistryOnAttach() { + ContainerLocator.SetContainerExtension(Mock.Of()); var region = new MockPresentationRegion() { Name = "MyRegion" }; var viewFactory = new MockRegionContentRegistry(); var view = new object(); @@ -35,6 +35,7 @@ public void ShouldGetViewsFromRegistryOnAttach() [Fact] public void ShouldGetViewsFromRegistryWhenRegisteringItAfterAttach() { + ContainerLocator.SetContainerExtension(Mock.Of()); var region = new MockPresentationRegion() { Name = "MyRegion" }; var viewFactory = new MockRegionContentRegistry(); var behavior = new AutoPopulateRegionBehavior(viewFactory) @@ -67,6 +68,7 @@ public void NullRegionThrows() [Fact] public void CanAttachBeforeSettingName() { + ContainerLocator.SetContainerExtension(Mock.Of()); var region = new MockPresentationRegion() { Name = null }; var viewFactory = new MockRegionContentRegistry(); var view = new object(); diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/DelayedRegionCreationBehaviorFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/DelayedRegionCreationBehaviorFixture.cs index 5c955580fb..c8544ab5b5 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/DelayedRegionCreationBehaviorFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/DelayedRegionCreationBehaviorFixture.cs @@ -1,7 +1,6 @@ - - using System; using System.Linq; +using System.Threading.Tasks; using System.Windows; using Prism.Navigation.Regions; using Prism.Navigation.Regions.Behaviors; @@ -103,7 +102,7 @@ public void RegionDoesNotGetCreatedTwiceWhenUpdatingRegions() } [StaFact] - public void BehaviorDoesNotPreventControlFromBeingGarbageCollected() + public async Task BehaviorDoesNotPreventControlFromBeingGarbageCollected() { var control = new MockFrameworkElement(); WeakReference controlWeakReference = new WeakReference(control); @@ -120,13 +119,14 @@ public void BehaviorDoesNotPreventControlFromBeingGarbageCollected() GC.KeepAlive(control); control = null; + await Task.Delay(10); GC.Collect(); Assert.False(controlWeakReference.IsAlive); } [StaFact] - public void BehaviorDoesNotPreventControlFromBeingGarbageCollectedWhenRegionWasCreated() + public async Task BehaviorDoesNotPreventControlFromBeingGarbageCollectedWhenRegionWasCreated() { var control = new MockFrameworkElement(); WeakReference controlWeakReference = new WeakReference(control); @@ -144,6 +144,7 @@ public void BehaviorDoesNotPreventControlFromBeingGarbageCollectedWhenRegionWasC GC.KeepAlive(control); control = null; + await Task.Delay(10); GC.Collect(); Assert.False(controlWeakReference.IsAlive); diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/RegionMemberLifetimeBehaviorFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/RegionMemberLifetimeBehaviorFixture.cs index 86b1cf1064..3802c1948a 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/RegionMemberLifetimeBehaviorFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/RegionMemberLifetimeBehaviorFixture.cs @@ -165,11 +165,11 @@ public virtual void RemovesRegionItemIfDataContextReturnsKeepAliveFalse() public virtual void RemovesOnlyDeactivatedItemsInRegionBasedOnDataContextKeepAlive() { // Arrange - var retionItemDataContextToKeepAlive = new Mock(); - retionItemDataContextToKeepAlive.Setup(i => i.KeepAlive).Returns(true); + var regionItemDataContextToKeepAlive = new Mock(); + regionItemDataContextToKeepAlive.Setup(i => i.KeepAlive).Returns(true); var regionItemToKeepAlive = new MockFrameworkElement(); - regionItemToKeepAlive.DataContext = retionItemDataContextToKeepAlive.Object; + regionItemToKeepAlive.DataContext = regionItemDataContextToKeepAlive.Object; Region.Add(regionItemToKeepAlive); Region.Activate(regionItemToKeepAlive); diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/ItemsControlRegionAdapterFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/ItemsControlRegionAdapterFixture.cs index 8d4405cd3f..e75d6b0297 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/ItemsControlRegionAdapterFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/ItemsControlRegionAdapterFixture.cs @@ -6,6 +6,8 @@ using System.Linq; using System.Windows.Controls; using System.Windows.Data; +using Moq; +using Prism.Ioc; using Prism.Navigation.Regions; using Prism.Wpf.Tests.Mocks; using Xunit; @@ -30,6 +32,7 @@ public void AdapterAssociatesItemsControlWithRegion() [StaFact] public void AdapterAssignsARegionThatHasAllViewsActive() { + ContainerLocator.SetContainerExtension(Mock.Of()); var control = new ItemsControl(); IRegionAdapter adapter = new ItemsControlRegionAdapter(null); diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/LocatorNavigationTargetHandlerFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/LocatorNavigationTargetHandlerFixture.cs index 99fa6bba3f..8f1c1afa5f 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/LocatorNavigationTargetHandlerFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/LocatorNavigationTargetHandlerFixture.cs @@ -1,9 +1,8 @@ - - using System; using System.Windows; using Moq; using Prism.Ioc; +using Prism.Ioc.Internals; using Prism.Navigation.Regions; using Xunit; @@ -18,6 +17,7 @@ public void WhenViewExistsAndDoesNotImplementINavigationAware_ThenReturnsView() // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -46,11 +46,12 @@ public void WhenRegionHasMultipleViews_ThenViewsWithMatchingTypeNameAreConsidere // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); var view1 = new TestView(); - var view2 = "view"; + var view2 = new Test2View(); region.Add(view1); region.Add(view2); @@ -76,11 +77,12 @@ public void WhenRegionHasMultipleViews_ThenViewsWithMatchingFullTypeNameAreConsi // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); var view1 = new TestView(); - var view2 = "view"; + var view2 = new Test2View(); region.Add(view1); region.Add(view2); @@ -106,6 +108,7 @@ public void WhenViewExistsAndImplementsINavigationAware_ThenViewIsQueriedForNavi // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -139,6 +142,7 @@ public void WhenViewExistsAndHasDataContextThatImplementsINavigationAware_ThenDa // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -174,6 +178,7 @@ public void WhenNoCurrentMatchingViewExists_ThenReturnsNewlyCreatedInstanceWithS // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -203,6 +208,7 @@ public void WhenViewExistsAndImplementsINavigationAware_ThenViewIsQueriedForNavi // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -240,6 +246,7 @@ public void WhenViewExistsAndHasDataContextThatImplementsINavigationAware_ThenDa { // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -274,6 +281,8 @@ public void WhenViewExistsAndHasDataContextThatImplementsINavigationAware_ThenDa public void WhenViewCannotBeCreated_ThenThrowsAnException() { var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); + containerMock.Setup(sl => sl.Resolve(typeof(object), typeof(TestView).Name)).Throws(); var region = new Region(); @@ -297,6 +306,7 @@ public void WhenViewAddedByHandlerDoesNotImplementINavigationAware_ThenReturnsVi { // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -340,6 +350,7 @@ public void WhenRequestingContentForNullRegion_ThenThrows() public void WhenRequestingContentForNullContext_ThenThrows() { var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -362,6 +373,8 @@ public TestRegionNavigationContentLoader(IContainerExtension container) } public class TestView { } + + public class Test2View { } } public class ActivationException : Exception diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/NavigationAsyncExtensionsFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/NavigationAsyncExtensionsFixture.cs index 8823bb4d77..82b8f851c3 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/NavigationAsyncExtensionsFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/NavigationAsyncExtensionsFixture.cs @@ -45,7 +45,8 @@ public void WhenNavigatingWithARelativeStringTarget_ThenNavigatesToRelativeUri() .Setup(nv => nv.RequestNavigate( It.Is(u => !u.IsAbsoluteUri && u.OriginalString == "relative"), - It.Is>(c => c != null))) + It.Is>(c => c != null), + It.IsAny())) .Verifiable(); string target = "relative"; @@ -63,7 +64,8 @@ public void WhenNavigatingWithAnAbsoluteStringTarget_ThenNavigatesToAbsoluteUri( .Setup(nv => nv.RequestNavigate( It.Is(u => u.IsAbsoluteUri && u.Host == "test" && u.AbsolutePath == "/path"), - It.Is>(c => c != null))) + It.Is>(c => c != null), + It.IsAny())) .Verifiable(); string target = "http://test/path"; @@ -96,7 +98,8 @@ public void WhenNavigatingWithAUri_ThenNavigatesToUriWithCallback() .Setup(nv => nv.RequestNavigate( target, - It.Is>(c => c != null))) + It.Is>(c => c != null), + It.IsAny())) .Verifiable(); diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionAdapterMappingsFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionAdapterMappingsFixture.cs index 7c9c6f4608..08f52055ed 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionAdapterMappingsFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionAdapterMappingsFixture.cs @@ -52,7 +52,7 @@ public void ShouldGetRegisteredMapping_UsingGenericControlAndAdapter() containerMock.Setup(c => c.Resolve(typeof(MockRegionAdapter))) .Returns(regionAdapter); ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => containerMock.Object); + ContainerLocator.SetContainerExtension(containerMock.Object); regionAdapterMappings.RegisterMapping(); diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionFixture.cs index 66d69e91d5..f126de6208 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionFixture.cs @@ -15,6 +15,7 @@ public class RegionFixture [Fact] public void WhenRegionConstructed_SortComparisonIsDefault() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); Assert.NotNull(region.SortComparison); @@ -24,6 +25,7 @@ public void WhenRegionConstructed_SortComparisonIsDefault() [Fact] public void CanAddContentToRegion() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); Assert.Empty(region.Views.Cast()); @@ -64,6 +66,7 @@ public void RemoveInexistentViewThrows() [Fact] public void RegionExposesCollectionOfContainedViews() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); object view = new object(); @@ -80,6 +83,7 @@ public void RegionExposesCollectionOfContainedViews() [Fact] public void CanAddAndRetrieveNamedViewInstance() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); object myView = new object(); region.Add(myView, "MyView"); @@ -105,6 +109,7 @@ public void AddingDuplicateNamedViewThrows() [Fact] public void AddNamedViewIsAlsoListedInViewsCollection() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); object myView = new object(); @@ -138,6 +143,7 @@ public void GetViewWithNullOrEmptyStringThrows() [Fact] public void AddNamedViewWithNullOrEmptyStringNameThrows() { + ContainerLocator.SetContainerExtension(Mock.Of()); var ex = Assert.Throws(() => { IRegion region = new Region(); @@ -150,6 +156,7 @@ public void AddNamedViewWithNullOrEmptyStringNameThrows() [Fact] public void GetViewReturnsNullAfterRemovingViewFromRegion() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); object myView = new object(); region.Add(myView, "MyView"); @@ -174,6 +181,7 @@ public void AddViewPassesSameScopeByDefaultToView() [Fact] public void AddViewPassesSameScopeByDefaultToNamedView() { + ContainerLocator.SetContainerExtension(Mock.Of()); var regionManager = new MockRegionManager(); IRegion region = new Region(); region.RegionManager = regionManager; @@ -185,8 +193,9 @@ public void AddViewPassesSameScopeByDefaultToNamedView() } [Fact] - public void AddViewPassesDiferentScopeWhenAdding() + public void AddViewPassesDifferentScopeWhenAdding() { + ContainerLocator.SetContainerExtension(Mock.Of()); var regionManager = new MockRegionManager(); IRegion region = new Region(); region.RegionManager = regionManager; @@ -200,6 +209,8 @@ public void AddViewPassesDiferentScopeWhenAdding() [Fact] public void CreatingNewScopesAsksTheRegionManagerForNewInstance() { + ContainerLocator.SetContainerExtension(Mock.Of()); + ContainerLocator.SetContainerExtension(Mock.Of()); var regionManager = new MockRegionManager(); IRegion region = new Region(); region.RegionManager = regionManager; @@ -213,6 +224,7 @@ public void CreatingNewScopesAsksTheRegionManagerForNewInstance() [Fact] public void AddViewReturnsExistingRegionManager() { + ContainerLocator.SetContainerExtension(Mock.Of()); var regionManager = new MockRegionManager(); IRegion region = new Region(); region.RegionManager = regionManager; @@ -290,6 +302,7 @@ public void ActivateNullViewThrows() [Fact] public void AddViewRaisesCollectionViewEvent() { + ContainerLocator.SetContainerExtension(Mock.Of()); bool viewAddedCalled = false; IRegion region = new Region(); @@ -309,6 +322,7 @@ public void AddViewRaisesCollectionViewEvent() [Fact] public void ViewAddedEventPassesTheViewAddedInTheEventArgs() { + ContainerLocator.SetContainerExtension(Mock.Of()); object viewAdded = null; IRegion region = new Region(); @@ -330,6 +344,7 @@ public void ViewAddedEventPassesTheViewAddedInTheEventArgs() [Fact] public void RemoveViewFiresViewRemovedEvent() { + ContainerLocator.SetContainerExtension(Mock.Of()); bool viewRemoved = false; IRegion region = new Region(); @@ -351,6 +366,7 @@ public void RemoveViewFiresViewRemovedEvent() [Fact] public void ViewRemovedEventPassesTheViewRemovedInTheEventArgs() { + ContainerLocator.SetContainerExtension(Mock.Of()); object removedView = null; IRegion region = new Region(); @@ -413,6 +429,7 @@ public void AddingSameViewTwiceThrows() [Fact] public void RemovingViewAlsoRemovesItFromActiveViews() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); object model = new object(); region.Add(model); @@ -427,6 +444,7 @@ public void RemovingViewAlsoRemovesItFromActiveViews() [Fact] public void ShouldGetNotificationWhenContextChanges() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); bool contextChanged = false; region.PropertyChanged += (s, args) => { if (args.PropertyName == "Context") contextChanged = true; }; @@ -563,7 +581,7 @@ public void NavigateDelegatesToIRegionNavigationService() var containerMock = new Mock(); containerMock.Setup(x => x.Resolve(typeof(IRegionNavigationService))).Returns(mockRegionNavigationService.Object); ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => containerMock.Object); + ContainerLocator.SetContainerExtension(containerMock.Object); // Act region.RequestNavigate(uri, navigationCallback, navigationParameters); @@ -580,6 +598,7 @@ public void NavigateDelegatesToIRegionNavigationService() [Fact] public void WhenViewsWithSortHintsAdded_RegionSortsViews() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); object view1 = new ViewOrder1(); @@ -599,6 +618,7 @@ public void WhenViewsWithSortHintsAdded_RegionSortsViews() [StaFact] public void WhenViewHasBeenRemovedAndRegionManagerPropertyCleared_ThenItCanBeAddedAgainToARegion() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region { RegionManager = new MockRegionManager() }; var view = new MockFrameworkElement(); diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerFixture.cs index 2a33a938b7..32aacd63bb 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerFixture.cs @@ -234,6 +234,7 @@ public void OnUpdatingRegions(object sender, EventArgs e) [Fact] public void WhenAddingRegions_ThenRegionsCollectionNotifiesUpdate() { + ContainerLocator.SetContainerExtension(Mock.Of()); var regionManager = new RegionManager(); var region1 = new Region { Name = "region1" }; @@ -262,6 +263,7 @@ public void WhenAddingRegions_ThenRegionsCollectionNotifiesUpdate() [Fact] public void WhenRemovingRegions_ThenRegionsCollectionNotifiesUpdate() { + ContainerLocator.SetContainerExtension(Mock.Of()); var regionManager = new RegionManager(); var region1 = new Region { Name = "region1" }; @@ -293,6 +295,7 @@ public void WhenRemovingRegions_ThenRegionsCollectionNotifiesUpdate() [Fact] public void WhenRemovingNonExistingRegion_ThenRegionsCollectionDoesNotNotifyUpdate() { + ContainerLocator.SetContainerExtension(Mock.Of()); var regionManager = new RegionManager(); var region1 = new Region { Name = "region1" }; @@ -346,7 +349,7 @@ public void CanRegisterViewType() }; var containerMock = new Mock(); containerMock.Setup(c => c.Resolve(typeof(IRegionViewRegistry))).Returns(mockRegionContentRegistry); - ContainerLocator.SetContainerExtension(() => containerMock.Object); + ContainerLocator.SetContainerExtension(containerMock.Object); var regionManager = new RegionManager(); @@ -382,7 +385,7 @@ public void CanRegisterViewTypeGeneric() var containerMock = new Mock(); containerMock.Setup(c => c.Resolve(typeof(IRegionViewRegistry))).Returns(mockRegionContentRegistry); ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => containerMock.Object); + ContainerLocator.SetContainerExtension(containerMock.Object); var regionManager = new RegionManager(); @@ -419,7 +422,7 @@ public void CanRegisterDelegate() }; var containerMock = new Mock(); containerMock.Setup(c => c.Resolve(typeof(IRegionViewRegistry))).Returns(mockRegionContentRegistry); - ContainerLocator.SetContainerExtension(() => containerMock.Object); + ContainerLocator.SetContainerExtension(containerMock.Object); var regionManager = new RegionManager(); diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerRequestNavigateFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerRequestNavigateFixture.cs index a6e1c4a270..cef8bba050 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerRequestNavigateFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerRequestNavigateFixture.cs @@ -1,5 +1,6 @@ using System; using Moq; +using Prism.Ioc; using Prism.Navigation; using Prism.Navigation.Regions; using Xunit; @@ -75,14 +76,14 @@ public void WhenNonExistentRegion_ReturnNavigationResultFalse() public void DelegatesCallToRegion_RegionSource() { regionManager.RequestNavigate(region, source); - mockRegion.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny>())); + mockRegion.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny>(), It.IsAny())); } [Fact] public void DelegatesCallToRegion_RegionTarget() { regionManager.RequestNavigate(region, sourceUri); - mockRegion.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny>())); + mockRegion.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny>(), It.IsAny())); } [Fact] @@ -103,14 +104,14 @@ public void DelegatesCallToRegion_RegionSourceUriParameters() public void DelegatesCallToRegion_RegionSourceCallback() { regionManager.RequestNavigate(region, source, callback); - mockRegion.Verify((r) => r.RequestNavigate(sourceUri, callback)); + mockRegion.Verify((r) => r.RequestNavigate(sourceUri, callback, It.IsAny())); } [Fact] public void DelegatesCallToRegion_RegionTargetCallback() { regionManager.RequestNavigate(region, sourceUri, callback); - mockRegion.Verify((r) => r.RequestNavigate(sourceUri, callback)); + mockRegion.Verify((r) => r.RequestNavigate(sourceUri, callback, It.IsAny())); } [Fact] diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionNavigationServiceFixture.new.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionNavigationServiceFixture.new.cs index 760a32cc76..f86ce03a98 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionNavigationServiceFixture.new.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionNavigationServiceFixture.new.cs @@ -10,7 +10,6 @@ namespace Prism.Wpf.Tests.Regions { - public class RegionNavigationServiceFixture { [Fact] @@ -280,6 +279,7 @@ public void WhenNavigating_NavigationIsRecordedInJournal() containerMock.Setup(x => x.Resolve(typeof(IRegionNavigationJournalEntry))).Returns(journalEntry); IContainerExtension container = containerMock.Object; + ContainerLocator.SetContainerExtension(container); RegionNavigationContentLoader contentLoader = new RegionNavigationContentLoader(container); var journalMock = new Mock(); @@ -733,6 +733,7 @@ public void WhenViewModelAcceptsNavigationOutAfterNewIncomingRequestIsReceived_T [Fact] public void BeforeNavigating_NavigatingEventIsRaised() { + ContainerLocator.SetContainerExtension(Mock.Of()); // Prepare object view = new object(); Uri viewUri = new Uri(view.GetType().Name, UriKind.Relative); diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionViewRegistryFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionViewRegistryFixture.cs index 2db2a9609c..106f8885f3 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionViewRegistryFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionViewRegistryFixture.cs @@ -17,6 +17,7 @@ public class RegionViewRegistryFixture public void CanRegisterContentAndRetrieveIt() { var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); containerMock.Setup(c => c.Resolve(typeof(MockContentObject))).Returns(new MockContentObject()); var registry = new RegionViewRegistry(containerMock.Object); @@ -52,6 +53,7 @@ public void ShouldRaiseEventWhenAddingContent() [Fact] public void CanRegisterContentAsDelegateAndRetrieveIt() { + ContainerLocator.SetContainerExtension(Mock.Of()); var registry = new RegionViewRegistry(null); var content = new MockContentObject(); @@ -121,6 +123,7 @@ public void RegisterViewWithRegion_ShouldHaveViewModel_ByDefault() ViewModelLocatorFixture.ResetViewModelLocationProvider(); var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); containerMock.Setup(c => c.Resolve(typeof(Mocks.Views.Mock))).Returns(new Mocks.Views.Mock()); containerMock.Setup(c => c.Resolve(typeof(Mocks.ViewModels.MockViewModel))).Returns(new Mocks.ViewModels.MockViewModel()); var registry = new RegionViewRegistry(containerMock.Object); @@ -143,6 +146,7 @@ public void RegisterViewWithRegion_ShouldNotHaveViewModel_OnOptOut() ViewModelLocatorFixture.ResetViewModelLocationProvider(); var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); containerMock.Setup(c => c.Resolve(typeof(Mocks.Views.MockOptOut))).Returns(new Mocks.Views.MockOptOut()); containerMock.Setup(c => c.Resolve(typeof(Mocks.ViewModels.MockOptOutViewModel))).Returns(new Mocks.ViewModels.MockOptOutViewModel()); var registry = new RegionViewRegistry(containerMock.Object); diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/SelectorRegionAdapterFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/SelectorRegionAdapterFixture.cs index ece315fdcc..b494b5750a 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/SelectorRegionAdapterFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/SelectorRegionAdapterFixture.cs @@ -3,6 +3,8 @@ using System; using System.Threading.Tasks; using System.Windows.Controls; +using Moq; +using Prism.Ioc; using Prism.Navigation.Regions; using Prism.Navigation.Regions.Behaviors; using Xunit; @@ -15,6 +17,7 @@ public class SelectorRegionAdapterFixture [StaFact] public void AdapterAddsSelectorItemsSourceSyncBehavior() { + ContainerLocator.SetContainerExtension(Mock.Of()); var control = new ListBox(); IRegionAdapter adapter = new TestableSelectorRegionAdapter(); @@ -29,6 +32,7 @@ public void AdapterAddsSelectorItemsSourceSyncBehavior() [StaFact] public async Task AdapterDoesNotPreventRegionFromBeingGarbageCollected() { + ContainerLocator.SetContainerExtension(Mock.Of()); var selector = new ListBox(); object model = new object(); IRegionAdapter adapter = new SelectorRegionAdapter(null); @@ -36,8 +40,8 @@ public async Task AdapterDoesNotPreventRegionFromBeingGarbageCollected() var region = adapter.Initialize(selector, "Region1"); region.Add(model); - WeakReference regionWeakReference = new WeakReference(region); - WeakReference controlWeakReference = new WeakReference(selector); + var regionWeakReference = new WeakReference(region); + var controlWeakReference = new WeakReference(selector); Assert.True(regionWeakReference.IsAlive); Assert.True(controlWeakReference.IsAlive); @@ -54,6 +58,7 @@ public async Task AdapterDoesNotPreventRegionFromBeingGarbageCollected() [StaFact] public void ActivatingTheViewShouldUpdateTheSelectedItem() { + ContainerLocator.SetContainerExtension(Mock.Of()); var selector = new ListBox(); var view1 = new object(); var view2 = new object(); @@ -78,6 +83,7 @@ public void ActivatingTheViewShouldUpdateTheSelectedItem() [StaFact] public void DeactivatingTheSelectedViewShouldUpdateTheSelectedItem() { + ContainerLocator.SetContainerExtension(Mock.Of()); var selector = new ListBox(); var view1 = new object(); IRegionAdapter adapter = new SelectorRegionAdapter(null); diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/SingleActiveRegionFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/SingleActiveRegionFixture.cs index 944a223444..6850578d37 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/SingleActiveRegionFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/SingleActiveRegionFixture.cs @@ -1,16 +1,16 @@ - - +using Moq; +using Prism.Ioc; using Prism.Navigation.Regions; using Xunit; namespace Prism.Wpf.Tests.Regions { - public class SingleActiveRegionFixture { [Fact] public void ActivatingNewViewDeactivatesCurrent() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new SingleActiveRegion(); var view = new object(); region.Add(view);