From c546c58f9ef46eea7adfa39e6bcf685ee1554d31 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Wed, 20 Nov 2019 22:46:01 +1100 Subject: [PATCH 1/2] feature: Add Prism DI extensions Change the locator to be accessible in a method Update dependencies where appropriate --- build.cake | 3 + src/Directory.build.props | 6 +- .../WinRT/Bitmaps/DispatcherMixin.cs | 2 +- ...xtensions.DependencyInjection.Tests.csproj | 2 +- ...soft.Extensions.DependencyInjection.csproj | 4 +- .../Splat.Microsoft.Extensions.Logging.csproj | 2 +- src/Splat.NLog/Splat.NLog.csproj | 2 +- .../Splat.Ninject.Tests.csproj | 2 +- src/Splat.Prism.Forms/PrismApplication.cs | 34 ++++ .../Splat.Prism.Forms.csproj | 15 ++ .../DependencyResolverTests.cs | 185 ++++++++++++++++++ .../Splat.Prism.Tests.csproj | 13 ++ src/Splat.Prism/Splat.Prism.csproj | 15 ++ src/Splat.Prism/SplatContainerExtension.cs | 114 +++++++++++ ...ovalTests.SplatProject.net472.approved.txt | 1 + ...ts.SplatProject.netcoreapp3.0.approved.txt | 1 + src/Splat.Tests/LocatorTests.cs | 4 +- .../Logging/BaseTests/LoggerBase.cs | 2 +- .../Logging/FullLoggers/NLogLoggerTests.cs | 2 +- .../Logging/FullLoggers/SerilogLoggerTests.cs | 4 +- .../WrappingFullLoggers/ConsoleLoggerTests.cs | 2 +- .../WrappingFullLoggers/Log4NetLoggerTests.cs | 2 +- .../MicrosoftExtensionsLoggingLoggerTests.cs | 2 +- src/Splat.Tests/Splat.Tests.csproj | 2 +- src/Splat.sln | 27 ++- src/Splat/AssemblyFinder.cs | 2 +- src/Splat/MemoizingMRUCache.cs | 2 +- .../DependencyResolverMixins.cs | 2 +- src/Splat/ServiceLocation/Locator.cs | 14 +- .../ModernDependencyResolver.cs | 8 +- src/stylecop.json | 3 + 31 files changed, 445 insertions(+), 34 deletions(-) create mode 100644 src/Splat.Prism.Forms/PrismApplication.cs create mode 100644 src/Splat.Prism.Forms/Splat.Prism.Forms.csproj create mode 100644 src/Splat.Prism.Tests/DependencyResolverTests.cs create mode 100644 src/Splat.Prism.Tests/Splat.Prism.Tests.csproj create mode 100644 src/Splat.Prism/Splat.Prism.csproj create mode 100644 src/Splat.Prism/SplatContainerExtension.cs diff --git a/build.cake b/build.cake index 7425778d6..61dd2499e 100644 --- a/build.cake +++ b/build.cake @@ -16,6 +16,8 @@ var packageWhitelist = new[] MakeAbsolute(File("./src/Splat.Serilog/Splat.Serilog.csproj")), MakeAbsolute(File("./src/Splat.SimpleInjector/Splat.SimpleInjector.csproj")), MakeAbsolute(File("./src/Splat.Drawing/Splat.Drawing.csproj")), + MakeAbsolute(File("./src/Splat.Prism/Splat.Prism.csproj")), + MakeAbsolute(File("./src/Splat.Prism.Forms/Splat.Prism.Forms.csproj")), }; var packageTestWhitelist = new[] @@ -26,6 +28,7 @@ var packageTestWhitelist = new[] MakeAbsolute(File("./src/Splat.Microsoft.Extensions.DependencyInjection.Tests/Splat.Microsoft.Extensions.DependencyInjection.Tests.csproj")), MakeAbsolute(File("./src/Splat.Ninject.Tests/Splat.Ninject.Tests.csproj")), MakeAbsolute(File("./src/Splat.SimpleInjector.Tests/Splat.SimpleInjector.Tests.csproj")), + MakeAbsolute(File("./src/Splat.Prism.Tests/Splat.Prism.Tests.csproj")), }; BuildParameters.SetParameters(context: Context, diff --git a/src/Directory.build.props b/src/Directory.build.props index adf21d4a1..79aef5ba5 100644 --- a/src/Directory.build.props +++ b/src/Directory.build.props @@ -62,12 +62,12 @@ - + - - + + diff --git a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/DispatcherMixin.cs b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/DispatcherMixin.cs index f4d736e13..d34af72b5 100644 --- a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/DispatcherMixin.cs +++ b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/DispatcherMixin.cs @@ -26,7 +26,7 @@ public static async Task RunTaskAsync(this CoreDispatcher dispatcher, Func taskCompletionSource.SetException(ex); } }); - return await taskCompletionSource.Task; + return await taskCompletionSource.Task.ConfigureAwait(false); } // There is no TaskCompletionSource so we use a bool that we throw away. diff --git a/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/Splat.Microsoft.Extensions.DependencyInjection.Tests.csproj b/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/Splat.Microsoft.Extensions.DependencyInjection.Tests.csproj index c62fe96cc..40414a53b 100644 --- a/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/Splat.Microsoft.Extensions.DependencyInjection.Tests.csproj +++ b/src/Splat.Microsoft.Extensions.DependencyInjection.Tests/Splat.Microsoft.Extensions.DependencyInjection.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.2 + netcoreapp3.0 $(NoWarn);1591;CA1707;SA1633;CA2000 false diff --git a/src/Splat.Microsoft.Extensions.DependencyInjection/Splat.Microsoft.Extensions.DependencyInjection.csproj b/src/Splat.Microsoft.Extensions.DependencyInjection/Splat.Microsoft.Extensions.DependencyInjection.csproj index 24b810d08..d10f0e04f 100644 --- a/src/Splat.Microsoft.Extensions.DependencyInjection/Splat.Microsoft.Extensions.DependencyInjection.csproj +++ b/src/Splat.Microsoft.Extensions.DependencyInjection/Splat.Microsoft.Extensions.DependencyInjection.csproj @@ -1,11 +1,11 @@ - + netstandard2.0 - + diff --git a/src/Splat.Microsoft.Extensions.Logging/Splat.Microsoft.Extensions.Logging.csproj b/src/Splat.Microsoft.Extensions.Logging/Splat.Microsoft.Extensions.Logging.csproj index 9847381a2..72777cbbb 100644 --- a/src/Splat.Microsoft.Extensions.Logging/Splat.Microsoft.Extensions.Logging.csproj +++ b/src/Splat.Microsoft.Extensions.Logging/Splat.Microsoft.Extensions.Logging.csproj @@ -9,7 +9,7 @@ Splat.Microsoft.Extensions.Logging - + diff --git a/src/Splat.NLog/Splat.NLog.csproj b/src/Splat.NLog/Splat.NLog.csproj index 10751b7bf..9d8dc37cb 100644 --- a/src/Splat.NLog/Splat.NLog.csproj +++ b/src/Splat.NLog/Splat.NLog.csproj @@ -9,7 +9,7 @@ Splat.NLog - + diff --git a/src/Splat.Ninject.Tests/Splat.Ninject.Tests.csproj b/src/Splat.Ninject.Tests/Splat.Ninject.Tests.csproj index 1d21f76e1..c007d92ce 100644 --- a/src/Splat.Ninject.Tests/Splat.Ninject.Tests.csproj +++ b/src/Splat.Ninject.Tests/Splat.Ninject.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.2 + netcoreapp3.0 $(NoWarn);1591;CA1707;SA1633;CA2000 false diff --git a/src/Splat.Prism.Forms/PrismApplication.cs b/src/Splat.Prism.Forms/PrismApplication.cs new file mode 100644 index 000000000..7dacf7f29 --- /dev/null +++ b/src/Splat.Prism.Forms/PrismApplication.cs @@ -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 +{ + /// + /// A application instance which supports Prism types. + /// + public abstract class PrismApplication : PrismApplicationBase + { + /// + /// Initializes a new instance of the class. + /// + /// An initializer for initializing the platform. + public PrismApplication(IPlatformInitializer initializer = null) + : base(initializer) + { + } + + /// + protected override IContainerExtension CreateContainerExtension() + { + return new SplatContainerExtension(); + } + } +} diff --git a/src/Splat.Prism.Forms/Splat.Prism.Forms.csproj b/src/Splat.Prism.Forms/Splat.Prism.Forms.csproj new file mode 100644 index 000000000..2592facb5 --- /dev/null +++ b/src/Splat.Prism.Forms/Splat.Prism.Forms.csproj @@ -0,0 +1,15 @@ + + + + netstandard2.0 + Prism adapter for Splat including Xamarin Forms adapters. + + + + + + + + + + diff --git a/src/Splat.Prism.Tests/DependencyResolverTests.cs b/src/Splat.Prism.Tests/DependencyResolverTests.cs new file mode 100644 index 000000000..1b4b6c486 --- /dev/null +++ b/src/Splat.Prism.Tests/DependencyResolverTests.cs @@ -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 +{ + /// + /// Tests to show the works correctly. + /// + public class DependencyResolverTests + { + /// + /// Should resolve the views. + /// + [Fact] + public void PrismDependencyResolver_Should_Resolve_Views() + { + var container = new SplatContainerExtension(); + container.Register(typeof(IViewFor), typeof(ViewOne)); + container.Register(typeof(IViewFor), typeof(ViewTwo)); + + var viewOne = Locator.Current.GetService(typeof(IViewFor)); + var viewTwo = Locator.Current.GetService(typeof(IViewFor)); + + viewOne.ShouldNotBeNull(); + viewOne.ShouldBeOfType(); + viewTwo.ShouldNotBeNull(); + viewTwo.ShouldBeOfType(); + } + + /// + /// Should resolve the views. + /// + [Fact] + public void PrismDependencyResolver_Should_Resolve_Named_View() + { + var container = new SplatContainerExtension(); + container.Register(typeof(IViewFor), typeof(ViewTwo), "Other"); + + var viewTwo = Locator.Current.GetService(typeof(IViewFor), "Other"); + + viewTwo.ShouldNotBeNull(); + viewTwo.ShouldBeOfType(); + } + + /// + /// Should resolve the view models. + /// + [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(); + var vmTwo = Locator.Current.GetService(); + + vmOne.ShouldNotBeNull(); + vmTwo.ShouldNotBeNull(); + } + + /// + /// Should resolve the screen. + /// + [Fact] + public void PrismDependencyResolver_Should_Resolve_Screen() + { + var builder = new SplatContainerExtension(); + builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen)); + + var screen = Locator.Current.GetService(); + + screen.ShouldNotBeNull(); + screen.ShouldBeOfType(); + } + + /// + /// Should unregister the screen. + /// + [Fact] + public void PrismDependencyResolver_Should_UnregisterCurrent_Screen() + { + var builder = new SplatContainerExtension(); + builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen)); + + Locator.Current.GetService().ShouldNotBeNull(); + + Locator.CurrentMutable.UnregisterCurrent(typeof(IScreen)); + + Locator.Current.GetService().ShouldBeNull(); + } + + /// + /// Should unregister the screen. + /// + [Fact] + public void PrismDependencyResolver_Should_UnregisterCurrent_Screen_With_Contract() + { + var builder = new SplatContainerExtension(); + builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen), nameof(MockScreen)); + + Locator.Current.GetService(nameof(MockScreen)).ShouldNotBeNull(); + + Locator.CurrentMutable.UnregisterCurrent(typeof(IScreen), nameof(MockScreen)); + + Locator.Current.GetService(nameof(MockScreen)).ShouldBeNull(); + } + + /// + /// Should unregister the screen. + /// + [Fact] + public void PrismDependencyResolver_Should_UnregisterAll_Screen() + { + var builder = new SplatContainerExtension(); + builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen)); + + Locator.Current.GetService().ShouldNotBeNull(); + + Locator.CurrentMutable.UnregisterAll(typeof(IScreen)); + + Locator.Current.GetService().ShouldBeNull(); + } + + /// + /// Should unregister the screen. + /// + [Fact] + public void PrismDependencyResolver_Should_UnregisterAll_Screen_With_Contract() + { + var builder = new SplatContainerExtension(); + builder.RegisterSingleton(typeof(IScreen), typeof(MockScreen), nameof(MockScreen)); + + Locator.Current.GetService(nameof(MockScreen)).ShouldNotBeNull(); + + Locator.CurrentMutable.UnregisterAll(typeof(IScreen), nameof(MockScreen)); + + Locator.Current.GetService(nameof(MockScreen)).ShouldBeNull(); + } + + /// + /// Check to ensure the correct logger is returned. + /// + /// + /// Introduced for Splat #331. + /// + [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(); + Assert.IsType(d); + } + + /// + /// Test that a pre-init logger isn't overriden. + /// + /// + /// Introduced for Splat #331. + /// + [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(); + Assert.IsType(d); + } + } +} diff --git a/src/Splat.Prism.Tests/Splat.Prism.Tests.csproj b/src/Splat.Prism.Tests/Splat.Prism.Tests.csproj new file mode 100644 index 000000000..ff35362f7 --- /dev/null +++ b/src/Splat.Prism.Tests/Splat.Prism.Tests.csproj @@ -0,0 +1,13 @@ + + + + netcoreapp3.0 + $(NoWarn);CA1707;CS1574 + + + + + + + + diff --git a/src/Splat.Prism/Splat.Prism.csproj b/src/Splat.Prism/Splat.Prism.csproj new file mode 100644 index 000000000..5835579f4 --- /dev/null +++ b/src/Splat.Prism/Splat.Prism.csproj @@ -0,0 +1,15 @@ + + + + netstandard2.0 + Prism adapter for Splat + + + + + + + + + + diff --git a/src/Splat.Prism/SplatContainerExtension.cs b/src/Splat.Prism/SplatContainerExtension.cs new file mode 100644 index 000000000..b23630d50 --- /dev/null +++ b/src/Splat.Prism/SplatContainerExtension.cs @@ -0,0 +1,114 @@ +// 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 Prism.Ioc; + +namespace Splat.Prism +{ + /// + /// A container for the Prism application. + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1316:Tuple element names should use correct casing", Justification = "Match Prism naming scheme.")] + public class SplatContainerExtension : IContainerExtension + { + /// + /// Initializes a new instance of the class. + /// + public SplatContainerExtension() + { + Locator.SetLocator(Instance); + } + + /// + /// Gets the dependency resolver. + /// + public IDependencyResolver Instance { get; } = new ModernDependencyResolver(); + + /// + public void FinalizeExtension() + { + Locator.SetLocator(new ModernDependencyResolver()); + } + + /// + public bool IsRegistered(Type type) + { + return Instance.HasRegistration(type); + } + + /// + public bool IsRegistered(Type type, string name) + { + return Instance.HasRegistration(type, name); + } + + /// + public IContainerRegistry Register(Type from, Type to) + { + Instance.Register(() => Activator.CreateInstance(to), from); + return this; + } + + /// + public IContainerRegistry Register(Type from, Type to, string name) + { + Instance.Register(() => Activator.CreateInstance(to), from, name); + return this; + } + + /// + public IContainerRegistry RegisterInstance(Type type, object instance) + { + Instance.RegisterConstant(instance, type); + return this; + } + + /// + public IContainerRegistry RegisterInstance(Type type, object instance, string name) + { + Instance.RegisterConstant(instance, type, name); + return this; + } + + /// + public IContainerRegistry RegisterSingleton(Type from, Type to) + { + Instance.RegisterLazySingleton(() => Activator.CreateInstance(to), from); + return this; + } + + /// + public IContainerRegistry RegisterSingleton(Type from, Type to, string name) + { + Instance.RegisterLazySingleton(() => Activator.CreateInstance(to), from, name); + return this; + } + + /// + public object Resolve(Type type) + { + return Instance.GetService(type); + } + + /// + public object Resolve(Type type, params (Type Type, object Instance)[] parameters) + { + throw new NotImplementedException(); + } + + /// + public object Resolve(Type type, string name) + { + return Instance.GetService(type, name); + } + + /// + public object Resolve(Type type, string name, params (Type Type, object Instance)[] parameters) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Splat.Tests/API/ApiApprovalTests.SplatProject.net472.approved.txt b/src/Splat.Tests/API/ApiApprovalTests.SplatProject.net472.approved.txt index 99e882820..44032b82b 100644 --- a/src/Splat.Tests/API/ApiApprovalTests.SplatProject.net472.approved.txt +++ b/src/Splat.Tests/API/ApiApprovalTests.SplatProject.net472.approved.txt @@ -420,6 +420,7 @@ namespace Splat public static Splat.IReadonlyDependencyResolver Current { get; } public static Splat.IMutableDependencyResolver CurrentMutable { get; } public static bool AreResolverCallbackChangedNotificationsEnabled() { } + public static Splat.IDependencyResolver GetLocator() { } public static System.IDisposable RegisterResolverCallbackChanged(System.Action callback) { } public static void SetLocator(Splat.IDependencyResolver dependencyResolver) { } public static System.IDisposable SuppressResolverCallbackChangedNotifications() { } diff --git a/src/Splat.Tests/API/ApiApprovalTests.SplatProject.netcoreapp3.0.approved.txt b/src/Splat.Tests/API/ApiApprovalTests.SplatProject.netcoreapp3.0.approved.txt index be2e00f8f..2556ba763 100644 --- a/src/Splat.Tests/API/ApiApprovalTests.SplatProject.netcoreapp3.0.approved.txt +++ b/src/Splat.Tests/API/ApiApprovalTests.SplatProject.netcoreapp3.0.approved.txt @@ -420,6 +420,7 @@ namespace Splat public static Splat.IReadonlyDependencyResolver Current { get; } public static Splat.IMutableDependencyResolver CurrentMutable { get; } public static bool AreResolverCallbackChangedNotificationsEnabled() { } + public static Splat.IDependencyResolver GetLocator() { } public static System.IDisposable RegisterResolverCallbackChanged(System.Action callback) { } public static void SetLocator(Splat.IDependencyResolver dependencyResolver) { } public static System.IDisposable SuppressResolverCallbackChangedNotifications() { } diff --git a/src/Splat.Tests/LocatorTests.cs b/src/Splat.Tests/LocatorTests.cs index 85a09ef3c..a452ab913 100644 --- a/src/Splat.Tests/LocatorTests.cs +++ b/src/Splat.Tests/LocatorTests.cs @@ -146,9 +146,9 @@ public void WithResolver_NotificationsNotSuppressedHappen() Locator.RegisterResolverCallbackChanged(notificationAction); - using (Locator.Internal.WithResolver(false)) + using (Locator.GetLocator().WithResolver(false)) { - using (Locator.Internal.WithResolver(false)) + using (Locator.GetLocator().WithResolver(false)) { } } diff --git a/src/Splat.Tests/Logging/BaseTests/LoggerBase.cs b/src/Splat.Tests/Logging/BaseTests/LoggerBase.cs index 65152a4d5..a1df38739 100644 --- a/src/Splat.Tests/Logging/BaseTests/LoggerBase.cs +++ b/src/Splat.Tests/Logging/BaseTests/LoggerBase.cs @@ -438,6 +438,6 @@ public void FatalTypeException_Should_Write_Message() /// /// The minimum log level. /// The logger. - protected abstract (T, IMockLogTarget) GetLogger(LogLevel minimumLogLevel); + protected abstract (T logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel); } } diff --git a/src/Splat.Tests/Logging/FullLoggers/NLogLoggerTests.cs b/src/Splat.Tests/Logging/FullLoggers/NLogLoggerTests.cs index f6c0c51aa..992428e98 100644 --- a/src/Splat.Tests/Logging/FullLoggers/NLogLoggerTests.cs +++ b/src/Splat.Tests/Logging/FullLoggers/NLogLoggerTests.cs @@ -36,7 +36,7 @@ public class NLogLoggerTests : FullLoggerTestBase }; /// - protected override (IFullLogger, IMockLogTarget) GetLogger(LogLevel minimumLogLevel) + protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) { var configuration = new LoggingConfiguration(); diff --git a/src/Splat.Tests/Logging/FullLoggers/SerilogLoggerTests.cs b/src/Splat.Tests/Logging/FullLoggers/SerilogLoggerTests.cs index 6b6ab67f6..ebb66df2a 100644 --- a/src/Splat.Tests/Logging/FullLoggers/SerilogLoggerTests.cs +++ b/src/Splat.Tests/Logging/FullLoggers/SerilogLoggerTests.cs @@ -108,13 +108,13 @@ public void Configuring_With_PreConfigured_Log_Should_Write_Message() } /// - protected override (IFullLogger, IMockLogTarget) GetLogger(LogLevel minimumLogLevel) + protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) { var (log, messages) = CreateSerilogger(minimumLogLevel); return (new SerilogFullLogger(log), messages); } - private static (Logger, IMockLogTarget) CreateSerilogger(LogLevel minimumLogLevel) + private static (Logger logger, IMockLogTarget mockTarget) CreateSerilogger(LogLevel minimumLogLevel) { var messages = new LogTarget(); diff --git a/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs b/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs index 789f33b3a..8bbdef2a1 100644 --- a/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs +++ b/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs @@ -20,7 +20,7 @@ namespace Splat.Tests.Logging public class ConsoleLoggerTests : FullLoggerTestBase { /// - protected override (IFullLogger, IMockLogTarget) GetLogger(LogLevel minimumLogLevel) + protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) { var outputWriter = new ConsoleWriter(); Console.SetOut(outputWriter); diff --git a/src/Splat.Tests/Logging/WrappingFullLoggers/Log4NetLoggerTests.cs b/src/Splat.Tests/Logging/WrappingFullLoggers/Log4NetLoggerTests.cs index e86b0bf98..d849c81b6 100644 --- a/src/Splat.Tests/Logging/WrappingFullLoggers/Log4NetLoggerTests.cs +++ b/src/Splat.Tests/Logging/WrappingFullLoggers/Log4NetLoggerTests.cs @@ -41,7 +41,7 @@ public class Log4NetLoggerTests : FullLoggerTestBase }; /// - protected override (IFullLogger, IMockLogTarget) GetLogger(LogLevel minimumLogLevel) + protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) { var logger = LogManager.GetLogger(typeof(Log4NetLoggerTests)); diff --git a/src/Splat.Tests/Logging/WrappingFullLoggers/MicrosoftExtensionsLoggingLoggerTests.cs b/src/Splat.Tests/Logging/WrappingFullLoggers/MicrosoftExtensionsLoggingLoggerTests.cs index b64770785..c849fece0 100644 --- a/src/Splat.Tests/Logging/WrappingFullLoggers/MicrosoftExtensionsLoggingLoggerTests.cs +++ b/src/Splat.Tests/Logging/WrappingFullLoggers/MicrosoftExtensionsLoggingLoggerTests.cs @@ -35,7 +35,7 @@ public class MicrosoftExtensionsLoggingLoggerTests : FullLoggerTestBase }; /// - protected override (IFullLogger, IMockLogTarget) GetLogger(LogLevel minimumLogLevel) + protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) { var mockLogger = new MockActualMicrosoftExtensionsLoggingLogger(_splat2MSLog[minimumLogLevel]); diff --git a/src/Splat.Tests/Splat.Tests.csproj b/src/Splat.Tests/Splat.Tests.csproj index edbefd3cd..827e9846f 100644 --- a/src/Splat.Tests/Splat.Tests.csproj +++ b/src/Splat.Tests/Splat.Tests.csproj @@ -1,7 +1,7 @@  - netstandard2.0;netcoreapp2.2 + netstandard2.0;netcoreapp3.0 $(NoWarn);1591;CA1707;SA1633;CA2000 diff --git a/src/Splat.sln b/src/Splat.sln index 99bb53a16..9a0d122a8 100644 --- a/src/Splat.sln +++ b/src/Splat.sln @@ -49,11 +49,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Splat.Common.Test", "Splat. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Splat.Android.Runner", "Splat.Android.Tests\Splat.Android.Runner.csproj", "{E7957867-EF5A-4765-A2CB-990A6ADFE6BB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Splat.Microsoft.Extensions.DependencyInjection", "Splat.Microsoft.Extensions.DependencyInjection\Splat.Microsoft.Extensions.DependencyInjection.csproj", "{168CC48D-C28C-48BA-B6F1-234A0C16597E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Splat.Microsoft.Extensions.DependencyInjection", "Splat.Microsoft.Extensions.DependencyInjection\Splat.Microsoft.Extensions.DependencyInjection.csproj", "{168CC48D-C28C-48BA-B6F1-234A0C16597E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Splat.Microsoft.Extensions.DependencyInjection.Tests", "Splat.Microsoft.Extensions.DependencyInjection.Tests\Splat.Microsoft.Extensions.DependencyInjection.Tests.csproj", "{85E5821D-CCC3-44DC-96A0-DFC02953943F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Splat.Microsoft.Extensions.DependencyInjection.Tests", "Splat.Microsoft.Extensions.DependencyInjection.Tests\Splat.Microsoft.Extensions.DependencyInjection.Tests.csproj", "{85E5821D-CCC3-44DC-96A0-DFC02953943F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Splat.Drawing", "Splat.Drawing\Splat.Drawing.csproj", "{694D2813-14FF-456A-B1E7-C5BB82AEE400}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Splat.Drawing", "Splat.Drawing\Splat.Drawing.csproj", "{694D2813-14FF-456A-B1E7-C5BB82AEE400}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Splat.Prism", "Splat.Prism\Splat.Prism.csproj", "{1D1FE7E6-10FF-4A7F-90D6-6E3696EC7D0D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Splat.Prism.Forms", "Splat.Prism.Forms\Splat.Prism.Forms.csproj", "{39195824-8E56-4240-A5A0-7FA4E12099D4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Splat.Prism.Tests", "Splat.Prism.Tests\Splat.Prism.Tests.csproj", "{905A96B2-03C9-4D08-8E8B-E5B0F7F9F33A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -139,6 +145,18 @@ Global {694D2813-14FF-456A-B1E7-C5BB82AEE400}.Debug|Any CPU.Build.0 = Debug|Any CPU {694D2813-14FF-456A-B1E7-C5BB82AEE400}.Release|Any CPU.ActiveCfg = Release|Any CPU {694D2813-14FF-456A-B1E7-C5BB82AEE400}.Release|Any CPU.Build.0 = Release|Any CPU + {1D1FE7E6-10FF-4A7F-90D6-6E3696EC7D0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1D1FE7E6-10FF-4A7F-90D6-6E3696EC7D0D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1D1FE7E6-10FF-4A7F-90D6-6E3696EC7D0D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1D1FE7E6-10FF-4A7F-90D6-6E3696EC7D0D}.Release|Any CPU.Build.0 = Release|Any CPU + {39195824-8E56-4240-A5A0-7FA4E12099D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {39195824-8E56-4240-A5A0-7FA4E12099D4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {39195824-8E56-4240-A5A0-7FA4E12099D4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {39195824-8E56-4240-A5A0-7FA4E12099D4}.Release|Any CPU.Build.0 = Release|Any CPU + {905A96B2-03C9-4D08-8E8B-E5B0F7F9F33A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {905A96B2-03C9-4D08-8E8B-E5B0F7F9F33A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {905A96B2-03C9-4D08-8E8B-E5B0F7F9F33A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {905A96B2-03C9-4D08-8E8B-E5B0F7F9F33A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -163,6 +181,9 @@ Global {168CC48D-C28C-48BA-B6F1-234A0C16597E} = {651320D6-1048-4F87-9D8E-75134FAFABDA} {85E5821D-CCC3-44DC-96A0-DFC02953943F} = {3F8EA9C2-D6D1-4B18-8670-DFC24B96972E} {694D2813-14FF-456A-B1E7-C5BB82AEE400} = {651320D6-1048-4F87-9D8E-75134FAFABDA} + {1D1FE7E6-10FF-4A7F-90D6-6E3696EC7D0D} = {651320D6-1048-4F87-9D8E-75134FAFABDA} + {39195824-8E56-4240-A5A0-7FA4E12099D4} = {651320D6-1048-4F87-9D8E-75134FAFABDA} + {905A96B2-03C9-4D08-8E8B-E5B0F7F9F33A} = {3F8EA9C2-D6D1-4B18-8670-DFC24B96972E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E833ED14-B971-4E09-B27E-76E99BC0FC10} diff --git a/src/Splat/AssemblyFinder.cs b/src/Splat/AssemblyFinder.cs index 085992a23..c11a624b2 100644 --- a/src/Splat/AssemblyFinder.cs +++ b/src/Splat/AssemblyFinder.cs @@ -41,7 +41,7 @@ public static T AttemptToLoadType(string fullTypeName) return (T)Activator.CreateInstance(type); } - return default(T); + return default; } } } diff --git a/src/Splat/MemoizingMRUCache.cs b/src/Splat/MemoizingMRUCache.cs index 460a3e074..d591a3569 100644 --- a/src/Splat/MemoizingMRUCache.cs +++ b/src/Splat/MemoizingMRUCache.cs @@ -162,7 +162,7 @@ public bool TryGet(TParam key, out TVal result) } else { - result = default(TVal); + result = default; } return ret; diff --git a/src/Splat/ServiceLocation/DependencyResolverMixins.cs b/src/Splat/ServiceLocation/DependencyResolverMixins.cs index 530be11df..d770e63fe 100644 --- a/src/Splat/ServiceLocation/DependencyResolverMixins.cs +++ b/src/Splat/ServiceLocation/DependencyResolverMixins.cs @@ -86,7 +86,7 @@ public static IDisposable WithResolver(this IDependencyResolver resolver, bool s var notificationDisposable = suppressResolverCallback ? Locator.SuppressResolverCallbackChangedNotifications() : new ActionDisposable(() => { }); - var origResolver = Locator.Internal; + var origResolver = Locator.GetLocator(); Locator.SetLocator(resolver); return new CompositeDisposable(new ActionDisposable(() => Locator.SetLocator(origResolver)), notificationDisposable); diff --git a/src/Splat/ServiceLocation/Locator.cs b/src/Splat/ServiceLocation/Locator.cs index e558708ed..a4a3969b6 100644 --- a/src/Splat/ServiceLocation/Locator.cs +++ b/src/Splat/ServiceLocation/Locator.cs @@ -4,8 +4,6 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; -using System.Threading; namespace Splat { @@ -36,8 +34,6 @@ static Locator() /// public static IMutableDependencyResolver CurrentMutable => InternalLocator.CurrentMutable; - internal static IDependencyResolver Internal => InternalLocator.Internal; - /// /// Gets or sets the current locator instance. /// Used mostly for testing purposes. @@ -53,6 +49,16 @@ public static void SetLocator(IDependencyResolver dependencyResolver) InternalLocator.SetLocator(dependencyResolver); } + /// + /// Gets the full locator. + /// Note you should use or in most situations. + /// + /// The locator. + public static IDependencyResolver GetLocator() + { + return InternalLocator.Internal; + } + /// /// This method allows libraries to register themselves to be set up /// whenever the dependency resolver changes. Applications should avoid diff --git a/src/Splat/ServiceLocation/ModernDependencyResolver.cs b/src/Splat/ServiceLocation/ModernDependencyResolver.cs index 87d84ea27..6290c72c7 100644 --- a/src/Splat/ServiceLocation/ModernDependencyResolver.cs +++ b/src/Splat/ServiceLocation/ModernDependencyResolver.cs @@ -106,11 +106,11 @@ public object GetService(Type serviceType, string contract = null) var pair = GetKey(serviceType, contract); if (!_registry.ContainsKey(pair)) { - return default(object); + return default; } - var ret = _registry[pair].Last(); - return ret(); + var ret = _registry[pair].LastOrDefault(); + return ret == null ? null : ret(); } /// @@ -213,7 +213,7 @@ protected virtual void Dispose(bool isDisposing) _isDisposed = true; } - private static (Type, string) GetKey( + private static (Type type, string contract) GetKey( Type serviceType, string contract = null) => (serviceType, contract ?? string.Empty); diff --git a/src/stylecop.json b/src/stylecop.json index 66c88ad69..8efa0b983 100644 --- a/src/stylecop.json +++ b/src/stylecop.json @@ -37,5 +37,8 @@ "usingDirectivesPlacement": "outsideNamespace", "systemUsingDirectivesFirst": true }, + "namingRules": { + "tupleElementNameCasing": "camelCase" + } } } From 92b3f8bea1e84818dcc3f5839c1bbf7492e8f894 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Wed, 20 Nov 2019 23:05:11 +1100 Subject: [PATCH 2/2] Set to use Cake 0.35.0 and also bump version --- build.config | 2 +- version.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.config b/build.config index 93fef6f50..745c70476 100644 --- a/build.config +++ b/build.config @@ -1,2 +1,2 @@ #!/usr/bin/env bash -CAKE_VERSION=0.34.1 +CAKE_VERSION=0.35.0 diff --git a/version.json b/version.json index 4c974ef97..b4896e131 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "version": "9.1", + "version": "9.2", "publicReleaseRefSpec": [ "^refs/heads/master$", // we release out of master "^refs/heads/preview/.*", // we release previews