Skip to content

Commit

Permalink
.Net 7 (#41)
Browse files Browse the repository at this point in the history
* Add .net 7

* Update code-base for net 7

* Update workflows
  • Loading branch information
trejjam authored Nov 8, 2022
1 parent 15bfe37 commit ba5f7cc
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 20 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
- name: Setup .Net 7.0.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
dotnet-quality: 'preview'
- uses: actions/checkout@v3
- name: Retore
run: dotnet restore --nologo src
Expand All @@ -39,7 +44,12 @@ jobs:
- name: Setup .Net 6.0.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.200'
dotnet-version: '6.0.x'
- name: Setup .Net 7.0.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
dotnet-quality: 'preview'
- name: Retore
run: dotnet restore --nologo src
- name: .Net Format
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/nightly-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
- name: Setup .Net 7.0.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
dotnet-quality: 'preview'
- uses: actions/checkout@v3
- name: Fetch all history for all tags and branches
run: git fetch --prune --unshallow
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
- name: Setup .Net 7.0.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
dotnet-quality: 'preview'
- uses: actions/checkout@v3
- name: Retore
run: dotnet restore --nologo src
Expand All @@ -33,6 +38,11 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
- name: Setup .Net 7.0.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
dotnet-quality: 'preview'
- name: Retore
run: dotnet restore --nologo src
- name: .Net Format
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
- name: Setup .Net 7.0.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
dotnet-quality: 'preview'
- uses: actions/checkout@v3
- name: Fetch all history for all tags and branches
run: git fetch --prune --unshallow
Expand Down
11 changes: 9 additions & 2 deletions src/Daktela.HttpClient/Daktela.HttpClient.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<PackageLicense>MIT</PackageLicense>
Expand All @@ -14,11 +14,18 @@

<Import Project="..\WarningConfiguration.targets" />

<ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="7.0.0" />
</ItemGroup>

</Project>
30 changes: 22 additions & 8 deletions tests/Daktela.HttpClient.Tests/Daktela.HttpClient.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>

Expand All @@ -21,6 +21,16 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
Expand All @@ -29,13 +39,17 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ public Action<HttpMessageHandlerBuilder> Configure(Action<HttpMessageHandlerBuil
next(builder);

var name = builder.Name;
var commaAt = name.IndexOf(',');
if (commaAt > 0)
if (name?.IndexOf(',') is { } commaAt and > 0)
{
name = name.Substring(0, commaAt);
name = name[..commaAt];
}

var scopeLogger = _loggerFactory.CreateLogger($"System.Net.Http.HttpClient.{name}.RequestScope");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static class EventIds
public static readonly EventId PipelineEnd = new(101, "RequestPipelineEnd");
}

private static readonly Func<ILogger, HttpMethod, Uri?, string, IDisposable> BeginRequestPipelineScopeDefine = LoggerMessage.DefineScope<HttpMethod, Uri?, string>(
private static readonly Func<ILogger, HttpMethod, Uri?, string, IDisposable?> BeginRequestPipelineScopeDefine = LoggerMessage.DefineScope<HttpMethod, Uri?, string>(
"HTTP {HttpMethod} {Uri} {CorrelationId}"
);

Expand All @@ -67,16 +67,16 @@ private static class EventIds
options: new LogDefineOptions { SkipEnabledCheck = true }
);

private readonly IDisposable _loggerScope;
private readonly IDisposable? _loggerScope;

private Log(IDisposable loggerScope)
private Log(IDisposable? loggerScope)
{
_loggerScope = loggerScope;
}

public void Dispose()
{
_loggerScope.Dispose();
_loggerScope?.Dispose();
}

public static Log BeginRequestPipelineScope(ILogger logger, HttpRequestMessage request)
Expand Down Expand Up @@ -143,7 +143,11 @@ private async Task<string> GetContent(HttpContent httpContent, CancellationToken
using var reader = new StreamReader(
compressionStream, Encoding.UTF8, detectEncodingFromByteOrderMarks: false, bufferSize: -1, leaveOpen: true
);
var content = await reader.ReadToEndAsync();
var content = await reader.ReadToEndAsync(
#if NET7_0_OR_GREATER
cancellationToken
#endif
);

stream.Seek(0, SeekOrigin.Begin);

Expand Down Expand Up @@ -184,7 +188,11 @@ private async Task<string> GetContent(HttpContent httpContent, CancellationToken
using var reader = new StreamReader(
streamContent, Encoding.UTF8, detectEncodingFromByteOrderMarks: false, bufferSize: -1, leaveOpen: true
);
var stringContent = await reader.ReadToEndAsync();
var stringContent = await reader.ReadToEndAsync(
#if NET7_0_OR_GREATER
cancellationToken
#endif
);

streamContent.Seek(0, SeekOrigin.Begin);

Expand Down

0 comments on commit ba5f7cc

Please sign in to comment.