-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Add Prism DI extensions (#431)
* feature: Add Prism DI extensions Change the locator to be accessible in a method Update dependencies where appropriate
- Loading branch information
1 parent
a727eb9
commit fb91958
Showing
33 changed files
with
447 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env bash | ||
CAKE_VERSION=0.34.1 | ||
CAKE_VERSION=0.35.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ons.DependencyInjection.Tests/Splat.Microsoft.Extensions.DependencyInjection.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...soft.Extensions.DependencyInjection/Splat.Microsoft.Extensions.DependencyInjection.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Prism; | ||
using Prism.Ioc; | ||
|
||
namespace Splat.Prism.Forms | ||
{ | ||
/// <summary> | ||
/// A application instance which supports Prism types. | ||
/// </summary> | ||
public abstract class PrismApplication : PrismApplicationBase | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PrismApplication"/> class. | ||
/// </summary> | ||
/// <param name="initializer">An initializer for initializing the platform.</param> | ||
public PrismApplication(IPlatformInitializer initializer = null) | ||
: base(initializer) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override IContainerExtension CreateContainerExtension() | ||
{ | ||
return new SplatContainerExtension(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<Description>Prism adapter for Splat including Xamarin Forms adapters.</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Prism.Forms" Version="7.2.0.1367" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Splat.Prism\Splat.Prism.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved. | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using Shouldly; | ||
using Splat.Common.Test; | ||
using Splat.Prism; | ||
using Xunit; | ||
|
||
namespace Splat.Prism.Tests | ||
{ | ||
/// <summary> | ||
/// Tests to show the <see cref="PrismDependencyResolver"/> works correctly. | ||
/// </summary> | ||
public class DependencyResolverTests | ||
{ | ||
/// <summary> | ||
/// Should resolve the views. | ||
/// </summary> | ||
[Fact] | ||
public void PrismDependencyResolver_Should_Resolve_Views() | ||
{ | ||
var container = new SplatContainerExtension(); | ||
container.Register(typeof(IViewFor<ViewModelOne>), typeof(ViewOne)); | ||
container.Register(typeof(IViewFor<ViewModelTwo>), typeof(ViewTwo)); | ||
|
||
var viewOne = Locator.Current.GetService(typeof(IViewFor<ViewModelOne>)); | ||
var viewTwo = Locator.Current.GetService(typeof(IViewFor<ViewModelTwo>)); | ||
|
||
viewOne.ShouldNotBeNull(); | ||
viewOne.ShouldBeOfType<ViewOne>(); | ||
viewTwo.ShouldNotBeNull(); | ||
viewTwo.ShouldBeOfType<ViewTwo>(); | ||
} | ||
|
||
/// <summary> | ||
/// Should resolve the views. | ||
/// </summary> | ||
[Fact] | ||
public void PrismDependencyResolver_Should_Resolve_Named_View() | ||
{ | ||
var container = new SplatContainerExtension(); | ||
container.Register(typeof(IViewFor<ViewModelTwo>), typeof(ViewTwo), "Other"); | ||
|
||
var viewTwo = Locator.Current.GetService(typeof(IViewFor<ViewModelTwo>), "Other"); | ||
|
||
viewTwo.ShouldNotBeNull(); | ||
viewTwo.ShouldBeOfType<ViewTwo>(); | ||
} | ||
|
||
/// <summary> | ||
/// Should resolve the view models. | ||
/// </summary> | ||
[Fact] | ||
public void PrismDependencyResolver_Should_Resolve_View_Models() | ||
{ | ||
var container = new SplatContainerExtension(); | ||
|
||
container.Register(typeof(ViewModelOne), typeof(ViewModelOne)); | ||
container.Register(typeof(ViewModelTwo), typeof(ViewModelTwo)); | ||
|
||
var vmOne = Locator.Current.GetService<ViewModelOne>(); | ||
var vmTwo = Locator.Current.GetService<ViewModelTwo>(); | ||
|
||
vmOne.ShouldNotBeNull(); | ||
vmTwo.ShouldNotBeNull(); | ||
} | ||
|
||
/// <summary> | ||
/// Should resolve the screen. | ||
/// </summary> | ||
[Fact] | ||
public void PrismDependencyResolver_Should_Resolve_Screen() | ||
{ | ||
var builder = new SplatContainerExtension(); | ||
builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen)); | ||
|
||
var screen = Locator.Current.GetService<IScreen>(); | ||
|
||
screen.ShouldNotBeNull(); | ||
screen.ShouldBeOfType<MockScreen>(); | ||
} | ||
|
||
/// <summary> | ||
/// Should unregister the screen. | ||
/// </summary> | ||
[Fact] | ||
public void PrismDependencyResolver_Should_UnregisterCurrent_Screen() | ||
{ | ||
var builder = new SplatContainerExtension(); | ||
builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen)); | ||
|
||
Locator.Current.GetService<IScreen>().ShouldNotBeNull(); | ||
|
||
Locator.CurrentMutable.UnregisterCurrent(typeof(IScreen)); | ||
|
||
Locator.Current.GetService<IScreen>().ShouldBeNull(); | ||
} | ||
|
||
/// <summary> | ||
/// Should unregister the screen. | ||
/// </summary> | ||
[Fact] | ||
public void PrismDependencyResolver_Should_UnregisterCurrent_Screen_With_Contract() | ||
{ | ||
var builder = new SplatContainerExtension(); | ||
builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen), nameof(MockScreen)); | ||
|
||
Locator.Current.GetService<IScreen>(nameof(MockScreen)).ShouldNotBeNull(); | ||
|
||
Locator.CurrentMutable.UnregisterCurrent(typeof(IScreen), nameof(MockScreen)); | ||
|
||
Locator.Current.GetService<IScreen>(nameof(MockScreen)).ShouldBeNull(); | ||
} | ||
|
||
/// <summary> | ||
/// Should unregister the screen. | ||
/// </summary> | ||
[Fact] | ||
public void PrismDependencyResolver_Should_UnregisterAll_Screen() | ||
{ | ||
var builder = new SplatContainerExtension(); | ||
builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen)); | ||
|
||
Locator.Current.GetService<IScreen>().ShouldNotBeNull(); | ||
|
||
Locator.CurrentMutable.UnregisterAll(typeof(IScreen)); | ||
|
||
Locator.Current.GetService<IScreen>().ShouldBeNull(); | ||
} | ||
|
||
/// <summary> | ||
/// Should unregister the screen. | ||
/// </summary> | ||
[Fact] | ||
public void PrismDependencyResolver_Should_UnregisterAll_Screen_With_Contract() | ||
{ | ||
var builder = new SplatContainerExtension(); | ||
builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen), nameof(MockScreen)); | ||
|
||
Locator.Current.GetService<IScreen>(nameof(MockScreen)).ShouldNotBeNull(); | ||
|
||
Locator.CurrentMutable.UnregisterAll(typeof(IScreen), nameof(MockScreen)); | ||
|
||
Locator.Current.GetService<IScreen>(nameof(MockScreen)).ShouldBeNull(); | ||
} | ||
|
||
/// <summary> | ||
/// Check to ensure the correct logger is returned. | ||
/// </summary> | ||
/// <remarks> | ||
/// Introduced for Splat #331. | ||
/// </remarks> | ||
[Fact] | ||
public void PrismDependencyResolver_Should_ReturnRegisteredLogger() | ||
{ | ||
var c = new SplatContainerExtension(); | ||
c.Register(typeof(ILogger), typeof(ConsoleLogger)); | ||
Locator.CurrentMutable.RegisterConstant( | ||
new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger())), | ||
typeof(ILogManager)); | ||
|
||
var d = Splat.Locator.Current.GetService<ILogManager>(); | ||
Assert.IsType<FuncLogManager>(d); | ||
} | ||
|
||
/// <summary> | ||
/// Test that a pre-init logger isn't overriden. | ||
/// </summary> | ||
/// <remarks> | ||
/// Introduced for Splat #331. | ||
/// </remarks> | ||
[Fact] | ||
public void PrismDependencyResolver_PreInit_Should_ReturnRegisteredLogger() | ||
{ | ||
var c = new SplatContainerExtension(); | ||
c.RegisterInstance(typeof(ILogManager), new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger()))); | ||
|
||
var d = Splat.Locator.Current.GetService<ILogManager>(); | ||
Assert.IsType<FuncLogManager>(d); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
<NoWarn>$(NoWarn);CA1707;CS1574</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Splat.Common.Test\Splat.Common.Test.csproj" /> | ||
<ProjectReference Include="..\Splat.Prism\Splat.Prism.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<Description>Prism adapter for Splat</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Prism.Core" Version="7.2.0.1367" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Splat\Splat.csproj" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.