Skip to content

Commit

Permalink
Merge pull request #42 from marcominerva/develop
Browse files Browse the repository at this point in the history
Update to .NET 8.0
  • Loading branch information
marcominerva committed Dec 13, 2023
2 parents e4868df + cd17825 commit 5301f89
Show file tree
Hide file tree
Showing 18 changed files with 42 additions and 59 deletions.
8 changes: 6 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ csharp_style_var_elsewhere = true:suggestion
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion

# Expression-bodied members
# Expression-bodied members preferences
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_indexers = true:silent
Expand Down Expand Up @@ -126,6 +126,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter

# Code-block preferences
csharp_style_prefer_top_level_statements = true:suggestion
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_braces = true:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_namespace_declarations = file_scoped:suggestion
Expand All @@ -147,6 +148,7 @@ csharp_using_directive_placement = outside_namespace:suggestion

# Struct preferences
csharp_style_prefer_readonly_struct = true:suggestion
csharp_style_prefer_readonly_struct_member = true:suggestion

#### C# Formatting Rules ####

Expand All @@ -161,6 +163,8 @@ csharp_new_line_between_query_expression_clauses = true
csharp_style_allow_embedded_statements_on_same_line_experimental = false:error
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:error
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent

# Indentation preferences
csharp_indent_block_contents = true
Expand Down Expand Up @@ -290,4 +294,4 @@ dotnet_diagnostic.IDE0058.severity = none
dotnet_diagnostic.IDE0010.severity = none

# IDE0072: Add missing cases
dotnet_diagnostic.IDE0072.severity = none
dotnet_diagnostic.IDE0072.severity = none
3 changes: 2 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
workflow_dispatch:

env:
NET_VERSION: '7.x'
NET_VERSION: '8.x'
PROJECT_NAME: src/OperationResults
PROJECT_FILE: OperationResults.csproj
RELEASE_NAME: OperationResultTools
Expand All @@ -16,6 +16,7 @@ jobs:
publish:
name: Publish on NuGet
runs-on: ubuntu-latest
if: ${{ github.repository_owner == vars.REPOSITORY_OWNER }}

steps:
- name: Checkout
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/publish_aspnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
workflow_dispatch:

env:
NET_VERSION: '7.x'
NET_VERSION: '8.x'
PROJECT_NAME: src/OperationResults.AspNetCore
PROJECT_FILE: OperationResults.AspNetCore.csproj
TAG_NAME: aspnetcore
Expand All @@ -17,6 +17,7 @@ jobs:
publish:
name: Publish on NuGet
runs-on: ubuntu-latest
if: ${{ github.repository_owner == vars.REPOSITORY_OWNER }}

steps:
- name: Checkout
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/publish_minimalapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
workflow_dispatch:

env:
NET_VERSION: '7.x'
NET_VERSION: '8.x'
PROJECT_NAME: src/OperationResults.AspNetCore.Http
PROJECT_FILE: OperationResults.AspNetCore.Http.csproj
TAG_NAME: minimalapi
Expand All @@ -16,7 +16,8 @@ env:
jobs:
publish:
name: Publish on NuGet
runs-on: ubuntu-latest
runs-on: ubuntu-latest
if: ${{ github.repository_owner == vars.REPOSITORY_OWNER }}

steps:
- name: Checkout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@ namespace OperationResults.Sample.Controllers;

[ApiController]
[Route("api/[controller]")]
public class ImageController : ControllerBase
public class ImageController(IImageService imageService) : ControllerBase
{
private readonly IImageService imageService;

public ImageController(IImageService imageService)
{
this.imageService = imageService;
}

[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,10 @@ namespace OperationResults.Sample.Controllers;
[ApiController]
[Route("api/[controller]")]
[Produces(MediaTypeNames.Application.Json)]
public class PeopleController : ControllerBase
public class PeopleController(IPeopleService peopleService) : ControllerBase
{
private readonly IPeopleService peopleService;

public PeopleController(IPeopleService peopleService)
{
this.peopleService = peopleService;
}

[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<Person>))]
[ProducesResponseType<IEnumerable<Person>>(StatusCodes.Status200OK)]
public async Task<IActionResult> GetList()
{
// You can collapse the following instructions into a single one.
Expand All @@ -42,7 +35,7 @@ public async Task<IActionResult> GetPerson(Guid id)
}

[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(Person))]
[ProducesResponseType<Person>(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> Save(Person person)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="TinyHelpers.AspNetCore" Version="2.0.20" />
<PackageReference Include="TinyHelpers.AspNetCore" Version="3.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.7" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
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>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@

namespace OperationResults.Sample.BusinessLayer.Services;

public class PeopleService : IPeopleService
public class PeopleService(ApplicationDbContext dbContext) : IPeopleService
{
private readonly ApplicationDbContext dbContext;

public PeopleService(ApplicationDbContext dbContext)
{
this.dbContext = dbContext;
}

public async Task<Result<IEnumerable<Person>>> GetAsync()
{
var people = await dbContext.People.AsNoTracking()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project>

<PropertyGroup>
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
<DebugType>embedded</DebugType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" PrivateAssets="All" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Authors>Marco Minerva</Authors>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Authors>Marco Minerva</Authors>
Expand Down
3 changes: 2 additions & 1 deletion src/OperationResults/OperationResults.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Authors>Marco Minerva</Authors>
<Company>Marco Minerva</Company>
<Product>OperationResults</Product>
Expand Down
8 changes: 4 additions & 4 deletions src/OperationResults/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ public static Result Ok()
=> new(success: true);

public static Result Fail(int failureReason, ValidationError validationError)
=> new(false, failureReason: failureReason, validationErrors: new ValidationError[] { validationError });
=> new(false, failureReason: failureReason, validationErrors: [validationError]);

public static Result Fail(int failureReason, string message, ValidationError validationError)
=> new(false, failureReason: failureReason, message: message, validationErrors: new ValidationError[] { validationError });
=> new(false, failureReason: failureReason, message: message, validationErrors: [validationError]);

public static Result Fail(int failureReason, string message, string detail, ValidationError validationError)
=> new(false, failureReason: failureReason, message: message, detail: detail, validationErrors: new ValidationError[] { validationError });
=> new(false, failureReason: failureReason, message: message, detail: detail, validationErrors: [validationError]);

public static Result Fail(int failureReason, Exception? error, ValidationError validationError)
=> new(false, failureReason: failureReason, error: error, validationErrors: new ValidationError[] { validationError });
=> new(false, failureReason: failureReason, error: error, validationErrors: [validationError]);

public static Result Fail(int failureReason, IEnumerable<ValidationError>? validationErrors = null)
=> new(false, failureReason: failureReason, validationErrors: validationErrors);
Expand Down
10 changes: 5 additions & 5 deletions src/OperationResults/Result{OfT}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ public static Result<T> Ok(T? content = default)
=> new(success: true, content);

public static Result<T> Fail(int failureReason, ValidationError validationError)
=> new(false, failureReason: failureReason, validationErrors: new ValidationError[] { validationError });
=> new(false, failureReason: failureReason, validationErrors: [validationError]);

public static Result<T> Fail(int failureReason, string message, ValidationError validationError)
=> new(false, failureReason: failureReason, message: message, validationErrors: new ValidationError[] { validationError });
=> new(false, failureReason: failureReason, message: message, validationErrors: [validationError]);

public static Result<T> Fail(int failureReason, string message, string detail, ValidationError validationError)
=> new(false, failureReason: failureReason, message: message, detail: detail, validationErrors: new ValidationError[] { validationError });
=> new(false, failureReason: failureReason, message: message, detail: detail, validationErrors: [validationError]);

public static Result<T> Fail(int failureReason, T content, ValidationError validationError)
=> new(false, failureReason: failureReason, content: content, validationErrors: new ValidationError[] { validationError });
=> new(false, failureReason: failureReason, content: content, validationErrors: [validationError]);

public static Result<T> Fail(int failureReason, Exception? error, ValidationError validationError)
=> new(false, failureReason: failureReason, error: error, validationErrors: new ValidationError[] { validationError });
=> new(false, failureReason: failureReason, error: error, validationErrors: [validationError]);

public static Result<T> Fail(int failureReason, IEnumerable<ValidationError>? validationErrors = null)
=> new(false, failureReason: failureReason, validationErrors: validationErrors);
Expand Down

0 comments on commit 5301f89

Please sign in to comment.