Skip to content

Commit 9f7b591

Browse files
committed
Implemented unified / async-only / nullable.
1 parent 5f8e9e1 commit 9f7b591

13 files changed

Lines changed: 129 additions & 160 deletions

Shuttle.Core.TransactionScope/.package/AssemblyInfo.cs.template

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
using System.Reflection;
22
using System.Runtime.InteropServices;
33

4-
#if NETSTANDARD
5-
[assembly: AssemblyTitle(".NET Standard")]
6-
#endif
7-
8-
#if NET6_0_OR_GREATER
9-
[assembly: AssemblyTitle(".NET 6.0 (or greater)")]
10-
#endif
11-
4+
[assembly: AssemblyTitle(".NET Unified Platform")]
125
[assembly: AssemblyVersion("#{SemanticVersionCore}#.0")]
136
[assembly: AssemblyCopyright("Copyright (c) #{Year}#, Eben Roux")]
147
[assembly: AssemblyProduct("Shuttle.Core.TransactionScope")]

Shuttle.Core.TransactionScope/.package/Shuttle.NuGetPackager.targets

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
2+
23
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
34
<PropertyGroup>
45
<PackageTasksPath Condition="'$(PackageTasksPath)' == ''">Shuttle.NuGetPackager.MSBuild.dll</PackageTasksPath>
@@ -9,4 +10,4 @@
910
<UsingTask AssemblyFile="$(PackageTasksPath)" TaskName="Shuttle.NuGetPackager.MSBuild.NuGet.SetNuGetPackageVersions" />
1011
<UsingTask AssemblyFile="$(PackageTasksPath)" TaskName="Shuttle.NuGetPackager.MSBuild.Zip" />
1112
<UsingTask AssemblyFile="$(PackageTasksPath)" TaskName="Shuttle.NuGetPackager.MSBuild.NuGet.SemanticVersion" />
12-
</Project>
13+
</Project>

Shuttle.Core.TransactionScope/.package/package.nuspec

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<package>
44
<metadata>
55
<id>Shuttle.Core.TransactionScope</id>
6-
<version>11.1.0</version>
6+
<version>20.0.0</version>
77
<authors>Eben Roux</authors>
88
<owners>Eben Roux</owners>
99
<license type="expression">BSD-3-Clause</license>
@@ -16,11 +16,11 @@
1616
<copyright>Copyright (c) 2024, Eben Roux</copyright>
1717
<tags>transactionscope</tags>
1818
<dependencies>
19-
<dependency id="Microsoft.Extensions.Configuration" version="7.0.0" />
20-
<dependency id="Microsoft.Extensions.DependencyInjection" version="7.0.0" />
21-
<dependency id="Microsoft.Extensions.Options" version="7.0.1" />
22-
<dependency id="Microsoft.Extensions.Options.ConfigurationExtensions" version="7.0.0" />
23-
<dependency id="Shuttle.Core.Contract" version="11.1.0" />
19+
<dependency id="Microsoft.Extensions.Configuration" version="8.0.0" />
20+
<dependency id="Microsoft.Extensions.DependencyInjection" version="8.0.1" />
21+
<dependency id="Microsoft.Extensions.Options" version="8.0.2" />
22+
<dependency id="Microsoft.Extensions.Options.ConfigurationExtensions" version="8.0.0" />
23+
<dependency id="Shuttle.Core.Contract" version="20.0.0" />
2424
</dependencies>
2525
</metadata>
2626
<files>
Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,50 @@
11
using System;
22
using System.Transactions;
33

4-
namespace Shuttle.Core.TransactionScope
4+
namespace Shuttle.Core.TransactionScope;
5+
6+
public class DefaultTransactionScope : ITransactionScope
57
{
6-
public class DefaultTransactionScope : ITransactionScope
7-
{
8-
private readonly bool _ignore;
8+
private readonly bool _ignore;
99

10-
private readonly System.Transactions.TransactionScope _scope;
10+
private readonly System.Transactions.TransactionScope _scope;
1111

12-
public DefaultTransactionScope(IsolationLevel isolationLevel, TimeSpan timeout)
13-
{
14-
Id = Guid.NewGuid();
12+
public DefaultTransactionScope(IsolationLevel isolationLevel, TimeSpan timeout)
13+
{
14+
Id = Guid.NewGuid();
1515

16-
_ignore = Transaction.Current != null;
16+
_ignore = Transaction.Current != null;
1717

18-
_scope = new System.Transactions.TransactionScope(TransactionScopeOption.RequiresNew,
19-
new TransactionOptions
20-
{
21-
IsolationLevel = isolationLevel,
22-
Timeout = timeout
23-
},
24-
TransactionScopeAsyncFlowOption.Enabled);
25-
}
18+
_scope = new(TransactionScopeOption.RequiresNew,
19+
new TransactionOptions
20+
{
21+
IsolationLevel = isolationLevel,
22+
Timeout = timeout
23+
},
24+
TransactionScopeAsyncFlowOption.Enabled);
25+
}
2626

27-
public void Dispose()
27+
public void Dispose()
28+
{
29+
try
2830
{
29-
try
30-
{
31-
_scope?.Dispose();
32-
}
33-
catch
34-
{
35-
// _ignore --- may be a bug in TransactionScope
36-
}
31+
_scope?.Dispose();
32+
}
33+
catch
34+
{
35+
// _ignore --- may be a bug in TransactionScope
3736
}
37+
}
3838

39-
public Guid Id { get; }
39+
public Guid Id { get; }
4040

41-
public void Complete()
41+
public void Complete()
42+
{
43+
if (_ignore)
4244
{
43-
if (_ignore)
44-
{
45-
return;
46-
}
47-
48-
_scope?.Complete();
45+
return;
4946
}
47+
48+
_scope?.Complete();
5049
}
5150
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using System;
22

3-
namespace Shuttle.Core.TransactionScope
3+
namespace Shuttle.Core.TransactionScope;
4+
5+
public interface ITransactionScope : IDisposable
46
{
5-
public interface ITransactionScope : IDisposable
6-
{
7-
Guid Id { get; }
8-
void Complete();
9-
}
7+
Guid Id { get; }
8+
void Complete();
109
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System;
22
using System.Transactions;
33

4-
namespace Shuttle.Core.TransactionScope
4+
namespace Shuttle.Core.TransactionScope;
5+
6+
public interface ITransactionScopeFactory
57
{
6-
public interface ITransactionScopeFactory
7-
{
8-
ITransactionScope Create();
9-
ITransactionScope Create(IsolationLevel isolationLevel, TimeSpan timeout);
10-
}
8+
ITransactionScope Create();
9+
ITransactionScope Create(IsolationLevel isolationLevel, TimeSpan timeout);
1110
}
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
using System;
22

3-
namespace Shuttle.Core.TransactionScope
3+
namespace Shuttle.Core.TransactionScope;
4+
5+
public class NullTransactionScope : ITransactionScope
46
{
5-
public class NullTransactionScope : ITransactionScope
6-
{
7-
public Guid Id => Guid.Empty;
7+
public Guid Id => Guid.Empty;
88

9-
public void Complete()
10-
{
11-
}
9+
public void Complete()
10+
{
11+
}
1212

13-
public void Dispose()
14-
{
15-
}
13+
public void Dispose()
14+
{
1615
}
1716
}
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
using System.Reflection;
22
using System.Runtime.InteropServices;
33

4-
#if NETSTANDARD
5-
[assembly: AssemblyTitle(".NET Standard")]
6-
#endif
7-
8-
#if NET6_0_OR_GREATER
9-
[assembly: AssemblyTitle(".NET 6.0 (or greater)")]
10-
#endif
11-
12-
[assembly: AssemblyVersion("11.1.0.0")]
4+
[assembly: AssemblyTitle(".NET Unified Platform")]
5+
[assembly: AssemblyVersion("20.0.0.0")]
136
[assembly: AssemblyCopyright("Copyright (c) 2024, Eben Roux")]
147
[assembly: AssemblyProduct("Shuttle.Core.TransactionScope")]
158
[assembly: AssemblyCompany("Eben Roux")]
169
[assembly: AssemblyConfiguration("Release")]
17-
[assembly: AssemblyInformationalVersion("11.1.0")]
10+
[assembly: AssemblyInformationalVersion("20.0.0")]
1811
[assembly: ComVisible(false)]

Shuttle.Core.TransactionScope/ServiceCollectionExtensions.cs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,32 @@
22
using Microsoft.Extensions.DependencyInjection;
33
using Shuttle.Core.Contract;
44

5-
namespace Shuttle.Core.TransactionScope
5+
namespace Shuttle.Core.TransactionScope;
6+
7+
public static class ServiceCollectionExtensions
68
{
7-
public static class ServiceCollectionExtensions
9+
public static IServiceCollection AddTransactionScope(this IServiceCollection services, Action<TransactionScopeBuilder>? builder = null)
810
{
9-
public static IServiceCollection AddTransactionScope(this IServiceCollection services, Action<TransactionScopeBuilder> builder = null)
10-
{
11-
Guard.AgainstNull(services, nameof(services));
11+
Guard.AgainstNull(services);
1212

13-
var transactionScopeBuilder = new TransactionScopeBuilder(services);
13+
var transactionScopeBuilder = new TransactionScopeBuilder(services);
1414

15-
builder?.Invoke(transactionScopeBuilder);
15+
builder?.Invoke(transactionScopeBuilder);
1616

17-
services.AddOptions<TransactionScopeOptions>().Configure(options =>
18-
{
19-
options.IsolationLevel = transactionScopeBuilder.Options.IsolationLevel;
20-
options.Timeout = transactionScopeBuilder.Options.Timeout;
21-
options.Enabled = transactionScopeBuilder.Options.Enabled;
22-
});
17+
services.AddOptions<TransactionScopeOptions>().Configure(options =>
18+
{
19+
options.IsolationLevel = transactionScopeBuilder.Options.IsolationLevel;
20+
options.Timeout = transactionScopeBuilder.Options.Timeout;
21+
options.Enabled = transactionScopeBuilder.Options.Enabled;
22+
});
2323

24-
if (services.Contains(ServiceDescriptor.Singleton<ITransactionScopeFactory, TransactionScopeFactory>()))
25-
{
26-
throw new InvalidOperationException(Resources.AddTransactionScopeFactoryException);
27-
}
24+
if (services.Contains(ServiceDescriptor.Singleton<ITransactionScopeFactory, TransactionScopeFactory>()))
25+
{
26+
throw new InvalidOperationException(Resources.AddTransactionScopeFactoryException);
27+
}
2828

29-
services.AddSingleton<ITransactionScopeFactory, TransactionScopeFactory>();
29+
services.AddSingleton<ITransactionScopeFactory, TransactionScopeFactory>();
3030

31-
return services;
32-
}
31+
return services;
3332
}
3433
}

Shuttle.Core.TransactionScope/Shuttle.Core.TransactionScope.csproj

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.1;net6.0</TargetFrameworks>
4+
<TargetFramework>net6.0</TargetFramework>
55
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
6+
<nullable>enable</nullable>
67
</PropertyGroup>
78

89
<ItemGroup>
@@ -14,11 +15,11 @@
1415
</ItemGroup>
1516

1617
<ItemGroup>
17-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
18-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
19-
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
20-
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
21-
<PackageReference Include="Shuttle.Core.Contract" Version="11.1.0" />
18+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
20+
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
21+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
22+
<PackageReference Include="Shuttle.Core.Contract" Version="20.0.0" />
2223
</ItemGroup>
2324

2425
<ItemGroup>

0 commit comments

Comments
 (0)