diff --git a/Source/Xamarin/Prism.Autofac.Forms.Tests/PrismApplicationFixture.cs b/Source/Xamarin/Prism.Autofac.Forms.Tests/PrismApplicationFixture.cs index 700930aff4..fee50e5366 100644 --- a/Source/Xamarin/Prism.Autofac.Forms.Tests/PrismApplicationFixture.cs +++ b/Source/Xamarin/Prism.Autofac.Forms.Tests/PrismApplicationFixture.cs @@ -13,6 +13,7 @@ using Xunit; using Autofac; using Autofac.Core.Registration; +using Prism.DI.Forms.Tests; #if TEST using Application = Prism.FormsApplication; #endif @@ -47,6 +48,16 @@ public void ResolveTypeRegisteredWithContainer() Assert.IsType(service); } + [Fact] + public void ResolveConcreteTypeNotRegisteredWithContainer() + { + var app = new PrismApplicationMock(); + Assert.True(app.Initialized); + var concreteType = app.Container.Resolve(); + Assert.NotNull(concreteType); + Assert.IsType(concreteType); + } + [Fact] public void ResolveTypeRegisteredWithDependencyService() { @@ -80,7 +91,7 @@ public void Module_Initialize() } [Fact] - public async Task Navigate_UnregisteredView_ThrowInvalidOperationException() + public async Task Navigate_UnregisteredView_ThrowNullReferenceException() { var app = new PrismApplicationMock(); var navigationService = ResolveAndSetRootPage(app); diff --git a/Source/Xamarin/Prism.DI.Forms.Tests/ConcreteTypeMock.cs b/Source/Xamarin/Prism.DI.Forms.Tests/ConcreteTypeMock.cs new file mode 100644 index 0000000000..e55d1bd30b --- /dev/null +++ b/Source/Xamarin/Prism.DI.Forms.Tests/ConcreteTypeMock.cs @@ -0,0 +1,6 @@ +namespace Prism.DI.Forms.Tests +{ + public class ConcreteTypeMock + { + } +} diff --git a/Source/Xamarin/Prism.DI.Forms.Tests/Prism.DI.Forms.Tests.projitems b/Source/Xamarin/Prism.DI.Forms.Tests/Prism.DI.Forms.Tests.projitems index a29f1b1efd..89df5d72e8 100644 --- a/Source/Xamarin/Prism.DI.Forms.Tests/Prism.DI.Forms.Tests.projitems +++ b/Source/Xamarin/Prism.DI.Forms.Tests/Prism.DI.Forms.Tests.projitems @@ -1,4 +1,4 @@ - + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) @@ -9,6 +9,7 @@ Prism.DI.Forms.Tests + diff --git a/Source/Xamarin/Prism.DryIoc.Forms.Tests/PrismApplicationFixture.cs b/Source/Xamarin/Prism.DryIoc.Forms.Tests/PrismApplicationFixture.cs index e99e7c9167..af99ba6f0d 100644 --- a/Source/Xamarin/Prism.DryIoc.Forms.Tests/PrismApplicationFixture.cs +++ b/Source/Xamarin/Prism.DryIoc.Forms.Tests/PrismApplicationFixture.cs @@ -12,6 +12,7 @@ using Prism.Navigation; using Xamarin.Forms; using Xunit; +using Prism.DI.Forms.Tests; #if TEST using Application = Prism.FormsApplication; #endif @@ -46,6 +47,16 @@ public void ResolveTypeRegisteredWithContainer() Assert.IsType(service); } + [Fact] + public void ResolveConcreteTypeNotRegisteredWithContainer() + { + var app = new PrismApplicationMock(); + Assert.True(app.Initialized); + var concreteType = app.Container.Resolve(); + Assert.NotNull(concreteType); + Assert.IsType(concreteType); + } + [Fact] public void ResolveTypeRegisteredWithDependencyService() { @@ -79,12 +90,12 @@ public void Module_Initialize() } [Fact] - public async Task Navigate_UnregisteredView_ThrowInvalidOperationException() + public async Task Navigate_UnregisteredView_ThrowArgumentOutOfRangeException() { var app = new PrismApplicationMock(); var navigationService = ResolveAndSetRootPage(app); - var exception = await Assert.ThrowsAsync(async () => await navigationService.NavigateAsync("missing")); - Assert.Contains("missing", exception.Message, StringComparison.OrdinalIgnoreCase); + var exception = await Assert.ThrowsAsync(async () => await navigationService.NavigateAsync("missing")); + //Assert.Contains("missing", exception.Message, StringComparison.OrdinalIgnoreCase); } [Fact] diff --git a/Source/Xamarin/Prism.DryIoc.Forms/Extensions/UnknownServiceResolverRule.cs b/Source/Xamarin/Prism.DryIoc.Forms/Extensions/UnknownServiceResolverRule.cs index 72ba2396a3..91f76b8765 100644 --- a/Source/Xamarin/Prism.DryIoc.Forms/Extensions/UnknownServiceResolverRule.cs +++ b/Source/Xamarin/Prism.DryIoc.Forms/Extensions/UnknownServiceResolverRule.cs @@ -1,5 +1,4 @@ -using System; -using System.Reflection; +using System.Reflection; using DryIoc; using Xamarin.Forms; @@ -10,21 +9,14 @@ namespace Prism.DryIoc.Extensions /// public static class UnknownServiceResolverRule { - public static Rules DependencyServiceResolverRule; - - static UnknownServiceResolverRule() + public static Factory DependencyServiceResolverRule(Request request) { - DependencyServiceResolverRule = Rules.Default.WithUnknownServiceResolvers(request => new DelegateFactory(_ => + return new DelegateFactory(_ => { - var targetType = request.ServiceType; - if (!targetType.GetTypeInfo().IsInterface) - { - return null; - } var method = typeof(DependencyService).GetTypeInfo().GetDeclaredMethod("Get"); - var genericMethod = method.MakeGenericMethod(targetType); + var genericMethod = method.MakeGenericMethod(request.ServiceType); return genericMethod.Invoke(null, new object[] { DependencyFetchTarget.GlobalInstance }); - })); + }); } } } \ No newline at end of file diff --git a/Source/Xamarin/Prism.DryIoc.Forms/PrismApplication.cs b/Source/Xamarin/Prism.DryIoc.Forms/PrismApplication.cs index c86ef24da2..b1aac263fe 100644 --- a/Source/Xamarin/Prism.DryIoc.Forms/PrismApplication.cs +++ b/Source/Xamarin/Prism.DryIoc.Forms/PrismApplication.cs @@ -65,7 +65,8 @@ protected override IModuleManager CreateModuleManager() /// An instance of protected virtual Rules CreateContainerRules() { - return UnknownServiceResolverRule.DependencyServiceResolverRule; + return Rules.Default.WithAutoConcreteTypeResolution() + .WithUnknownServiceResolvers(request => UnknownServiceResolverRule.DependencyServiceResolverRule(request)); } protected override void ConfigureContainer()