Skip to content

Commit

Permalink
.NET 9 (#250)
Browse files Browse the repository at this point in the history
* Removed old dotnet versions, now targeting 8 & 9. Upgraded dependencies

* Upgraded OpenTelemetry & Swashbuckle

* Upgrade reference assemblies

* Use dotnet 8 / 9 features in the code, collection expressions etc

* Cleanup root namespaces

* dotnet 9 optimizations
  • Loading branch information
mhelleborg authored Nov 13, 2024
1 parent 1222e5f commit 4a99379
Show file tree
Hide file tree
Showing 155 changed files with 490 additions and 447 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/dotnet-library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
9.0.x
- name: Setup dotCover
run: dotnet tool install JetBrains.dotCover.GlobalTool -g
- name: Setup report generator
Expand Down
3 changes: 2 additions & 1 deletion Benchmarks/Harness/Harness.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>Dolittle.Benchmarks.Harness</RootNamespace>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public override void IterationSetup()
.Create("63c974e5-1381-4757-a5de-04ef9d729d16")
.WithConcurrency(Concurrency)
.Partitioned()
.Handle<AnEvent>((evt, ctx) => { })
.Handle<LastEvent>((evt, ctx) => { _finishedProcessing.SetResult(true); })));
.Handle<AnEvent>((_, _) => { })
.Handle<LastEvent>((_, _) => { _finishedProcessing.SetResult(true); })));
_eventStore = client.EventStore.ForTenant(TenantId.Development);
_eventStore.CommitEvent(_anEvent, "source").Wait();
_eventSources = new EventSourceId[EventSourceIds];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Dolittle.Benchmarks.SDK.EventStore.with_1_tenant;

public class committing_100_events_with_warmup : SingleRuntimeSetup
{

public override void IterationSetup()
{
base.IterationSetup();
}

[Benchmark(OperationsPerInvoke = 100)]
public async Task Commit100Loop()
{
Expand Down
4 changes: 1 addition & 3 deletions Benchmarks/SDK/Program.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using BenchmarkDotNet.Running;
using Dolittle.Benchmarks.SDK.EventStore.with_1_tenant;

namespace Dolittle.Benchmarks.SDK;

// Inspiration from https://github.com/dotnet/performance/blob/main/src/harness/BenchmarkDotNet.Extensions/Extensions.cs

class Program
sealed class Program
{
static int Main(string[] args)
{
var argsList = new List<string>(args);
var config = BenchmarkConfig.Create();
// return BenchmarkSwitcher
// .FromAssembly(typeof(Program).Assembly)
Expand Down
2 changes: 1 addition & 1 deletion Benchmarks/SDK/SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Optimize>true</Optimize>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>Dolittle.Benchmarks.SDK</RootNamespace>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Benchmarks/SDK/SingleRuntimeSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task GlobalCleanup()
}

public IDolittleClient GetConnectedClient(bool withDiscovery = false)
=> GetConnectedClient(_ => _.WithoutDiscovery());
=> GetConnectedClient(builder => builder.WithoutDiscovery());
public IDolittleClient GetConnectedClient(SetupDolittleClient setup)
=> Host.CreateDefaultBuilder().UseDolittle(setup).Build().GetDolittleClient(_ => _
.WithRuntimeOn("localhost", (ushort)_singleRuntime!.Endpoints.Private)
Expand Down
4 changes: 2 additions & 2 deletions Benchmarks/SDK/SummaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public static class SummaryExtensions
public static int ToExitCode(this IEnumerable<Summary> summaries)
{
var enumerable = summaries as Summary[] ?? summaries.ToArray();
if (!enumerable.Any())
if (enumerable.Length == 0)
{
return 1;
}
return enumerable.Any(summary => summary.HasCriticalValidationErrors || summary.Reports.Any(report => !report.BuildResult.IsBuildSuccess || !report.AllMeasurements.Any()))
? 1
: 0;
}
}
}
30 changes: 15 additions & 15 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="1.1.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.1.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="9.0.0" />
<PackageVersion Include="Microsoft.Reactive.Testing" Version="6.0.1" />
<PackageVersion Include="MongoDB.Driver" Version="3.0.0" />
<PackageVersion Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="2.0.0" />
Expand All @@ -50,19 +50,19 @@
<PackageVersion Include="Proto.OpenTelemetry" Version="1.7.1-alpha.0.1" />
<PackageVersion Include="Proto.Cluster" Version="1.7.1-alpha.0.1" />
<PackageVersion Include="Google.Protobuf" Version="3.28.3" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.9.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="7.0.0" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.Formats.Asn1" Version="8.0.1" />
<PackageVersion Include="System.Collections.Immutable" Version="9.0.0" />
<PackageVersion Include="System.Formats.Asn1" Version="9.0.0" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Reactive" Version="6.0.1" />
<PackageVersion Include="System.Security.Claims" Version="4.3.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="OpenTelemetry.Api" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Api" Version="1.10.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.10.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.10.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.9.0-beta.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
Expand Down
2 changes: 1 addition & 1 deletion Samples/ASP.NET.Tests/ASP.NET.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
2 changes: 1 addition & 1 deletion Samples/ASP.NET/ASP.NET.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions Samples/ASP.NET/Customers/CustomersController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -27,7 +26,7 @@ public async Task<string[]> GetDishesEaten([FromRoute] string customer)
.Get(customer, HttpContext.RequestAborted)
.ConfigureAwait(false);

return state?.Dishes ?? Array.Empty<string>();
return state?.Dishes ?? [];
}

[HttpGet("All")]
Expand Down
2 changes: 1 addition & 1 deletion Samples/ASP.NET/Customers/DishesEaten.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Customers;
[Projection("185107c2-f897-40c8-bb06-643b3642f230")]
public class DishesEaten: ReadModel
{
public string[] Dishes { get; set; } = {};
public string[] Dishes { get; set; } = [];

public void On(DishEaten evt, ProjectionContext ctx)
{
Expand Down
2 changes: 1 addition & 1 deletion Samples/DependencyInjection/DependencyInjection.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>


Expand Down
2 changes: 1 addition & 1 deletion Samples/MongoDBProjections/MongoDBProjections.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Samples/Tutorials/Aggregates/Aggregates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Samples/Tutorials/EventHorizon/Consumer/Consumer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Samples/Tutorials/EventHorizon/Producer/Producer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Samples/Tutorials/GettingStarted/Kitchen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Samples/Tutorials/Projections/Projections.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
7 changes: 3 additions & 4 deletions Source/Aggregates/Actors/AggregateActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Diagnostics;
using Dolittle.SDK.Aggregates.Internal;
using Dolittle.SDK.Async;
using Dolittle.SDK.Events;
Expand Down Expand Up @@ -91,7 +90,7 @@ async Task OnStarted(IContext context)
catch (Exception e)
{
_logger.FailedToCreate(e, typeof(TAggregate));
Activity.Current?.RecordError(e);
Activity.Current?.AddException(e);
throw;
}
}
Expand All @@ -110,7 +109,7 @@ async Task OnPerform(Perform<TAggregate> perform, IContext context)
}
catch (Exception e)
{
Activity.Current?.RecordError(e);
Activity.Current?.AddException(e);
context.Respond(new Try<bool>(e));
}
finally
Expand All @@ -132,7 +131,7 @@ async Task OnPerformAndRespond(PerformAndRespond<TAggregate> performAndRespond,
}
catch (Exception e)
{
Activity.Current?.RecordError(e);
Activity.Current?.AddException(e);
context.Respond(new Try<object?>(e));
}
finally
Expand Down
2 changes: 1 addition & 1 deletion Source/Aggregates/Actors/AggregateClusterKindFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static class AggregateClusterKindFactory
public static ClusterKind CreateKind(IServiceProvider serviceProvider, Type aggregateRootType)
{
var createKind = typeof(AggregateClusterKindFactory<>).MakeGenericType(aggregateRootType).GetMethod(nameof(CreateKind));
return (ClusterKind)createKind!.Invoke(null, new object[] { serviceProvider })!;
return (ClusterKind)createKind!.Invoke(null, [serviceProvider])!;
}
}

Expand Down
7 changes: 2 additions & 5 deletions Source/Aggregates/Actors/ClusterIdentityMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ public static ClusterIdentity GetClusterIdentity<TAggregate>(TenantId tenantId,

public static (TenantId, EventSourceId) GetTenantAndEventSourceId(ClusterIdentity clusterIdentity)
{
if (clusterIdentity is null)
{
throw new ArgumentNullException(nameof(clusterIdentity));
}
var separator = clusterIdentity.Identity.IndexOf(":", StringComparison.Ordinal);
ArgumentNullException.ThrowIfNull(clusterIdentity);
var separator = clusterIdentity.Identity.IndexOf(':');

if(separator == -1)
{
Expand Down
6 changes: 3 additions & 3 deletions Source/Aggregates/AggregateRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Dolittle.SDK.Aggregates;
/// </summary>
public abstract class AggregateRoot
{
readonly List<AppliedEvent> _appliedEvents = new();
readonly List<AppliedEvent> _appliedEvents = [];
EventSourceId? _eventSourceId;

/// <summary>
Expand Down Expand Up @@ -195,7 +195,7 @@ internal async Task RehydrateInternal(IAsyncEnumerable<CommittedAggregateEvents>
var eventContent = @event.Content;
if (onMethods.TryGetValue(eventContent.GetType(), out var handleMethod))
{
handleMethod.Invoke(this, new[] { eventContent });
handleMethod.Invoke(this, [eventContent]);
}
}
}
Expand Down Expand Up @@ -226,7 +226,7 @@ void InvokeOnMethod(object @event)
{
if (this.TryGetOnMethod(@event, out var handleMethod))
{
handleMethod.Invoke(this, new[] { @event });
handleMethod.Invoke(this, [@event]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Aggregates/AggregateRootOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Diagnostics;
using Dolittle.SDK.Aggregates.Actors;
using Dolittle.SDK.Async;
using Dolittle.SDK.Diagnostics;
using Dolittle.SDK.Events;
using Dolittle.SDK.Tenancy;
using Proto;
Expand Down
4 changes: 2 additions & 2 deletions Source/Aggregates/Internal/AggregateWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Diagnostics;
using Dolittle.SDK.Diagnostics;
using Dolittle.SDK.Events;
using Dolittle.SDK.Events.Builders;
using Dolittle.SDK.Events.Store;
Expand Down Expand Up @@ -140,7 +140,7 @@ Task Rehydrate(TAggregate aggregateRoot, AggregateRootId aggregateRootId, Cancel
/// <returns></returns>
static IEnumerable<EventType> GetEventTypes(IEventTypes eventTypes)
=> IsStateLess
? Enumerable.Empty<EventType>()
? []
: AggregateRootMetadata<TAggregate>.MethodsPerEventType.Keys.Select(eventTypes.GetFor);

Task<CommittedAggregateEvents> CommitAppliedEvents(TAggregate aggregateRoot, AggregateRootId aggregateRootId)
Expand Down
Loading

0 comments on commit 4a99379

Please sign in to comment.