Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding nullability to project #293

Merged
merged 7 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Format Code
run: dotnet format analyzers Content/CarterService.sln --verbosity diagnostic
- name: Build Source
run: dotnet build Content/src/CarterService.csproj -v quiet --configuration Release
run: dotnet build Content/src/CarterService.csproj --configuration Release
- name: Build Tests
run: dotnet build Content/src/CarterService.csproj -v quiet --configuration Release
run: dotnet build Content/tests/CarterService.Tests.csproj --configuration Release
- name: Test
run: dotnet test Content/tests/CarterService.Tests.csproj -v quiet --configuration Release
run: dotnet test Content/tests/CarterService.Tests.csproj --configuration Release
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
1 change: 1 addition & 0 deletions Content/src/CarterService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<AssemblyName>CarterService</AssemblyName>
<OutputType>Exe</OutputType>
<LangVersion>Latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Remove=".editorconfig" />
Expand Down
10 changes: 5 additions & 5 deletions Content/src/Entities/Internal/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace CarterService.Entities;
namespace CarterService.Entities.Internal;

/// <summary>
/// This is obtained from the appsettings.json on Startup
/// </summary>
public record AppSettings
{
public CacheConfig Cache { get; init; }
public RouteDefinition RouteDefinition { get; init; }
public HealthDefinition HealthDefinition { get; init; }
public string[] ServerUrls { get; init; }
public CacheConfig Cache { get; init; } = new();
public RouteDefinition RouteDefinition { get; init; } = new();
public HealthDefinition HealthDefinition { get; init; } = new();
public string[] ServerUrls { get; init; } = [];
}
2 changes: 1 addition & 1 deletion Content/src/Entities/Internal/CacheConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CarterService.Entities;
namespace CarterService.Entities.Internal;

public record CacheConfig
{
Expand Down
14 changes: 7 additions & 7 deletions Content/src/Entities/Internal/FailedResponse.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
using System;

namespace CarterService.Entities;
namespace CarterService.Entities.Internal;

public record FailedResponse
{
public FailedResponse(Exception ex)
{
Message = ex.Message;
#if DEBUG
StackTrace = ex.StackTrace;
Source = ex.Source;
TargetMethod = ex.TargetSite.Name;
StackTrace = ex.StackTrace ?? string.Empty;
Source = ex.Source ?? string.Empty;
TargetMethod = ex.TargetSite?.Name ?? string.Empty;
#endif
}

public string Message { get; set; }
#if DEBUG
public string StackTrace { get; set; }
public string Source { get; set; }
public string TargetMethod { get; set; }
public string StackTrace { get; set; } = string.Empty;
public string Source { get; set; } = string.Empty;
public string TargetMethod { get; set; } = string.Empty;
#endif
}
10 changes: 5 additions & 5 deletions Content/src/Entities/Internal/HealthDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace CarterService.Entities;
namespace CarterService.Entities.Internal;

public record HealthDefinition
{
public string Endpoint { get; init; }
public string Name { get; init; }
public string HealthyMessage { get; init; }
public string[] Tags { get; init; }
public string Endpoint { get; init; } = string.Empty;
public string Name { get; init; } = string.Empty;
public string HealthyMessage { get; init; } = string.Empty;
public string[] Tags { get; init; } = [];
}
6 changes: 3 additions & 3 deletions Content/src/Entities/Internal/RouteDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace CarterService.Entities;
namespace CarterService.Entities.Internal;

public record RouteDefinition
{
public string RouteSuffix { get; init; }
public string Version { get; init; }
public string RouteSuffix { get; init; } = string.Empty;
public string Version { get; init; } = string.Empty;
}
2 changes: 1 addition & 1 deletion Content/src/Extensions/HttpContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Carter.Cache;
using Carter.ModelBinding;
using Carter.Response;
using CarterService.Entities;
using CarterService.Entities.Internal;
using Microsoft.AspNetCore.Http;

namespace CarterService.Extensions;
Expand Down
2 changes: 1 addition & 1 deletion Content/src/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class TypeExtensions
internal static Type GetAnyElementType(this Type type)
{
if (type.IsArray)
return type.GetElementType();
return type.GetElementType()!;

if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
return type.GetGenericArguments()[0];
Expand Down
2 changes: 1 addition & 1 deletion Content/src/Extensions/WebApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Carter.OpenApi;
using CarterService.Entities;
using CarterService.Entities.Internal;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
Expand Down
4 changes: 2 additions & 2 deletions Content/src/Modules/HelloModule.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Carter;
using Carter.OpenApi;
using CarterService.Entities;
using CarterService.Entities.Internal;
using CarterService.Extensions;
using CarterService.Repository;
using CarterService.Repositories;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
Expand Down
2 changes: 1 addition & 1 deletion Content/src/Modules/MainModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Threading.Tasks;
using Carter;
using CarterService.Entities;
using CarterService.Entities.Internal;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
Expand Down
4 changes: 2 additions & 2 deletions Content/src/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Carter;
using Carter.Cache;
using CarterService.Entities;
using CarterService.Entities.Internal;
using CarterService.Extensions;
using CarterService.Repository;
using CarterService.Repositories;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
Expand Down
2 changes: 1 addition & 1 deletion Content/src/Repositories/HelloRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CarterService.Repository;
namespace CarterService.Repositories;

public class HelloRepository : IHelloRepository
{
Expand Down
2 changes: 1 addition & 1 deletion Content/src/Repositories/IHelloRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CarterService.Repository;
namespace CarterService.Repositories;

public interface IHelloRepository
{
Expand Down
3 changes: 1 addition & 2 deletions Content/src/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"WriteTo": [
{ "Name": "Console" }
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"AllowedHosts": "*"
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
},
"AppSettings": {
"Cache": {
Expand Down
3 changes: 1 addition & 2 deletions Content/src/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"WriteTo": [
{ "Name": "Console" }
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"AllowedHosts": "*"
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
},
"AppSettings": {
"Cache": {
Expand Down
1 change: 1 addition & 0 deletions Content/tests/CarterService.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<LangVersion>Latest</LangVersion>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Content/tests/Unit/HelloTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using CarterService.Repository;
using CarterService.Repositories;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
Expand Down
Loading