Skip to content

Commit

Permalink
- GuardAgainstRecordNotFound / .net standard 2.0 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
eben-roux committed Jun 21, 2019
1 parent 10999c1 commit ef00e3d
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 15 deletions.
10 changes: 5 additions & 5 deletions Shuttle.Core.Data.Tests/Shuttle.Core.Data.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Include="Moq" Version="4.12.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" Condition="'$(TargetFramework)' == 'netcoreapp2.1'" />
<PackageReference Include="System.Data.SqlClient" Version="4.5.1" Condition="'$(TargetFramework)' == 'netcoreapp2.1'" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" Condition="'$(TargetFramework)' == 'netcoreapp2.1'" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 0 additions & 3 deletions Shuttle.Core.Data/.build/package.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,20 @@
<dependency id="Shuttle.Core.Configuration" version="{Shuttle.Core.Configuration-version}" />
<dependency id="Shuttle.Core.Container" version="{Shuttle.Core.Container-version}" />
<dependency id="Shuttle.Core.Logging" version="{Shuttle.Core.Logging-version}" />
<dependency id="Shuttle.Core.Threading" version="{Shuttle.Core.Threading-version}" />
</group>

<group targetFramework="netstandard2.0">
<dependency id="System.Configuration.ConfigurationManager" version="{System.Configuration.ConfigurationManager-version}" />
<dependency id="Shuttle.Core.Configuration" version="{Shuttle.Core.Configuration-version}" />
<dependency id="Shuttle.Core.Container" version="{Shuttle.Core.Container-version}" />
<dependency id="Shuttle.Core.Logging" version="{Shuttle.Core.Logging-version}" />
<dependency id="Shuttle.Core.Threading" version="{Shuttle.Core.Threading-version}" />
</group>

<group targetFramework="netcoreapp2.1">
<dependency id="System.Configuration.ConfigurationManager" version="{System.Configuration.ConfigurationManager-version}" />
<dependency id="Shuttle.Core.Configuration" version="{Shuttle.Core.Configuration-version}" />
<dependency id="Shuttle.Core.Container" version="{Shuttle.Core.Container-version}" />
<dependency id="Shuttle.Core.Logging" version="{Shuttle.Core.Logging-version}" />
<dependency id="Shuttle.Core.Threading" version="{Shuttle.Core.Threading-version}" />
</group>
</dependencies>
</metadata>
Expand Down
6 changes: 6 additions & 0 deletions Shuttle.Core.Data/DatabaseContextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
23 changes: 21 additions & 2 deletions Shuttle.Core.Data/DbConnectionFactory.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
using System.Data;
using System.Data.Common;
using Shuttle.Core.Logging;
#if (NETSTANDARD)
using Shuttle.Core.Contract;
#endif

namespace Shuttle.Core.Data
{
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)
Expand Down
4 changes: 2 additions & 2 deletions Shuttle.Core.Data/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
15 changes: 15 additions & 0 deletions Shuttle.Core.Data/RecordNotFoundExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Shuttle.Core.Data
{
public static class RecordNotFoundExtensions
{
public static T GuardAgainstRecordNotFound<T>(this T entity, object id) where T : class
{
if (entity == null)
{
throw RecordNotFoundException.For<T>(id);
}

return entity;
}
}
}
7 changes: 4 additions & 3 deletions Shuttle.Core.Data/Shuttle.Core.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

<ItemGroup>
<PackageReference Include="Shuttle.Core.Configuration" Version="10.0.3" />
<PackageReference Include="Shuttle.Core.Container" Version="10.0.11" />
<PackageReference Include="Shuttle.Core.Container" Version="11.0.0" />
<PackageReference Include="Shuttle.Core.Logging" Version="10.0.3" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Configuration" Condition="'$(TargetFramework)' != 'netstandard2.0' and '$(TargetFramework)' != 'netcoreapp2.0' and '$(TargetFramework)' != 'netcoreapp2.1'" />
<Reference Include="System.Configuration" Condition="'$(TargetFramework)' == 'net461'" />
<Reference Include="System.Transactions" Condition="'$(TargetFramework)' != 'netstandard2.0'" />
</ItemGroup>

Expand All @@ -40,6 +40,7 @@
</ItemGroup>

<ItemGroup>
<Compile Remove="IDbProviderFactories.cs" Condition="'$(TargetFramework)' != 'netstandard2.0' and '$(TargetFramework)' != 'netcoreapp2.0' and '$(TargetFramework)' != 'netcoreapp2.1'" />
<Compile Remove="DefaultProviderFactories.cs" Condition="'$(TargetFramework)' != 'netstandard2.0'" />
<Compile Remove="IDbProviderFactories.cs" Condition="'$(TargetFramework)' != 'netstandard2.0'" />
</ItemGroup>
</Project>

0 comments on commit ef00e3d

Please sign in to comment.