From ef00e3d77e551c1f37171c56d8bcf39446d6a9db Mon Sep 17 00:00:00 2001 From: Eben Date: Fri, 21 Jun 2019 09:02:29 +0200 Subject: [PATCH] - GuardAgainstRecordNotFound / .net standard 2.0 fix --- .../Shuttle.Core.Data.Tests.csproj | 10 ++++---- Shuttle.Core.Data/.build/package.nuspec | 3 --- Shuttle.Core.Data/DatabaseContextFactory.cs | 6 +++++ Shuttle.Core.Data/DbConnectionFactory.cs | 23 +++++++++++++++++-- Shuttle.Core.Data/Properties/AssemblyInfo.cs | 4 ++-- Shuttle.Core.Data/RecordNotFoundExtensions.cs | 15 ++++++++++++ Shuttle.Core.Data/Shuttle.Core.Data.csproj | 7 +++--- 7 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 Shuttle.Core.Data/RecordNotFoundExtensions.cs diff --git a/Shuttle.Core.Data.Tests/Shuttle.Core.Data.Tests.csproj b/Shuttle.Core.Data.Tests/Shuttle.Core.Data.Tests.csproj index 01b23dc..b552236 100644 --- a/Shuttle.Core.Data.Tests/Shuttle.Core.Data.Tests.csproj +++ b/Shuttle.Core.Data.Tests/Shuttle.Core.Data.Tests.csproj @@ -17,12 +17,12 @@ - - - - + + + + - + diff --git a/Shuttle.Core.Data/.build/package.nuspec b/Shuttle.Core.Data/.build/package.nuspec index 43ddf75..d772ee4 100644 --- a/Shuttle.Core.Data/.build/package.nuspec +++ b/Shuttle.Core.Data/.build/package.nuspec @@ -19,7 +19,6 @@ - @@ -27,7 +26,6 @@ - @@ -35,7 +33,6 @@ - diff --git a/Shuttle.Core.Data/DatabaseContextFactory.cs b/Shuttle.Core.Data/DatabaseContextFactory.cs index ec74e3d..3c9b7f8 100644 --- a/Shuttle.Core.Data/DatabaseContextFactory.cs +++ b/Shuttle.Core.Data/DatabaseContextFactory.cs @@ -112,9 +112,15 @@ public IDatabaseContextFactory ConfigureWith(IDbConnection dbConnection) return this; } +#if (!NETSTANDARD) public static IDatabaseContextFactory Default() { var dbConnectionFactory = new DbConnectionFactory(); +#else + public static IDatabaseContextFactory Default(IDbProviderFactories dbProviderFactories) + { + var dbConnectionFactory = new DbConnectionFactory(dbProviderFactories); +#endif return new DatabaseContextFactory(new ConnectionConfigurationProvider(), dbConnectionFactory, new DbCommandFactory(), new ThreadStaticDatabaseContextCache()); } diff --git a/Shuttle.Core.Data/DbConnectionFactory.cs b/Shuttle.Core.Data/DbConnectionFactory.cs index 784fc74..9f83abd 100644 --- a/Shuttle.Core.Data/DbConnectionFactory.cs +++ b/Shuttle.Core.Data/DbConnectionFactory.cs @@ -1,6 +1,9 @@ using System.Data; using System.Data.Common; using Shuttle.Core.Logging; +#if (NETSTANDARD) +using Shuttle.Core.Contract; +#endif namespace Shuttle.Core.Data { @@ -8,14 +11,30 @@ public class DbConnectionFactory : IDbConnectionFactory { private readonly ILog _log; - public DbConnectionFactory() +#if (!NETSTANDARD) + public DbConnectionFactory() { _log = Log.For(this); } +#else + private readonly IDbProviderFactories _providerFactories; + + public DbConnectionFactory(IDbProviderFactories providerFactories) + { + Guard.AgainstNull(providerFactories, nameof(providerFactories)); + + _providerFactories = providerFactories; + _log = Log.For(this); + } +#endif public IDbConnection CreateConnection(string providerName, string connectionString) { - var dbProviderFactory = DbProviderFactories.GetFactory(providerName); +#if (!NETSTANDARD) + var dbProviderFactory = DbProviderFactories.GetFactory(providerName); +#else + var dbProviderFactory = _providerFactories.GetFactory(providerName); +#endif var connection = dbProviderFactory.CreateConnection(); if (connection == null) diff --git a/Shuttle.Core.Data/Properties/AssemblyInfo.cs b/Shuttle.Core.Data/Properties/AssemblyInfo.cs index a658cf4..19eca66 100644 --- a/Shuttle.Core.Data/Properties/AssemblyInfo.cs +++ b/Shuttle.Core.Data/Properties/AssemblyInfo.cs @@ -13,10 +13,10 @@ [assembly: AssemblyTitle(".NET Standard 2.0")] #endif -[assembly: AssemblyVersion("11.0.1.0")] +[assembly: AssemblyVersion("11.0.2.0")] [assembly: AssemblyCopyright("Copyright © Eben Roux 2019")] [assembly: AssemblyProduct("Shuttle.Core.Data")] [assembly: AssemblyCompany("Shuttle")] [assembly: AssemblyConfiguration("Release")] -[assembly: AssemblyInformationalVersion("11.0.1")] +[assembly: AssemblyInformationalVersion("11.0.2")] [assembly: ComVisible(false)] diff --git a/Shuttle.Core.Data/RecordNotFoundExtensions.cs b/Shuttle.Core.Data/RecordNotFoundExtensions.cs new file mode 100644 index 0000000..aa488f7 --- /dev/null +++ b/Shuttle.Core.Data/RecordNotFoundExtensions.cs @@ -0,0 +1,15 @@ +namespace Shuttle.Core.Data +{ + public static class RecordNotFoundExtensions + { + public static T GuardAgainstRecordNotFound(this T entity, object id) where T : class + { + if (entity == null) + { + throw RecordNotFoundException.For(id); + } + + return entity; + } + } +} \ No newline at end of file diff --git a/Shuttle.Core.Data/Shuttle.Core.Data.csproj b/Shuttle.Core.Data/Shuttle.Core.Data.csproj index 790b351..a1dc1bd 100644 --- a/Shuttle.Core.Data/Shuttle.Core.Data.csproj +++ b/Shuttle.Core.Data/Shuttle.Core.Data.csproj @@ -14,13 +14,13 @@ - + - + @@ -40,6 +40,7 @@ - + +