Skip to content

Commit

Permalink
Add SignalR as websocket presentation (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkz-soft authored Nov 26, 2022
1 parent 392bba1 commit 1202c13
Show file tree
Hide file tree
Showing 39 changed files with 351 additions and 76 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,22 @@ jobs:
run: dotnet build -c Release --no-restore
- name: Application Test
run: dotnet test ./tests/NKZSoft.Template.Application.Tests --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage
# - name: REST Test
# run: dotnet test ./tests/NKZSoft.Template.Presentation.REST.Tests --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage
- name: REST Test
run: dotnet test ./tests/NKZSoft.Template.Presentation.REST.Tests --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage
- name: GraphQL Test
run: dotnet test ./tests/NKZSoft.Template.Presentation.GraphQL.Tests --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage
- name: SignalR Test
run: dotnet test ./tests/NKZSoft.Template.Presentation.SignalR.Tests --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage
- name: GRPC Test
run: dotnet test ./tests/NKZSoft.Template.Presentation.GRPC.Tests --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage
- name: Merge test results
run: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator "-reports:coverage/**/coverage.cobertura.xml" "-targetdir:coverage/result" -reporttypes:Cobertura
- name: Code Coverage Report
uses: irongut/[email protected]
with:
filename: coverage/**/coverage.cobertura.xml
filename: coverage/result/*.xml
badge: true
fail_below_min: true
format: markdown
Expand Down
14 changes: 14 additions & 0 deletions NKZSoft.Template.sln
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NKZSoft.Template.Events", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NKZSoft.Template.MessageBrokers.RabbitMq", "src\NKZSoft.Template.MessageBrokers.RabbitMq\NKZSoft.Template.MessageBrokers.RabbitMq.csproj", "{748E8208-2140-40FB-BDD2-145F27C762BC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NKZSoft.Template.Presentation.SignalR", "src\NKZSoft.Template.Presentation.SignalR\NKZSoft.Template.Presentation.SignalR.csproj", "{69A8CB59-91D9-4550-B94B-803A9BF2CE1F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NKZSoft.Template.Presentation.SignalR.Tests", "tests\NKZSoft.Template.Presentation.SignalR.Tests\NKZSoft.Template.Presentation.SignalR.Tests.csproj", "{F1059472-8C5E-4DE2-9ED9-27FCB0F5352B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -140,6 +144,14 @@ Global
{748E8208-2140-40FB-BDD2-145F27C762BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{748E8208-2140-40FB-BDD2-145F27C762BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{748E8208-2140-40FB-BDD2-145F27C762BC}.Release|Any CPU.Build.0 = Release|Any CPU
{69A8CB59-91D9-4550-B94B-803A9BF2CE1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69A8CB59-91D9-4550-B94B-803A9BF2CE1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69A8CB59-91D9-4550-B94B-803A9BF2CE1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69A8CB59-91D9-4550-B94B-803A9BF2CE1F}.Release|Any CPU.Build.0 = Release|Any CPU
{F1059472-8C5E-4DE2-9ED9-27FCB0F5352B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F1059472-8C5E-4DE2-9ED9-27FCB0F5352B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1059472-8C5E-4DE2-9ED9-27FCB0F5352B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1059472-8C5E-4DE2-9ED9-27FCB0F5352B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -168,6 +180,8 @@ Global
{EBF07FE3-4F11-4EF2-AF4E-5F748BAB5AA1} = {664D406C-2F83-48F0-BFC3-408D5CB53C65}
{D02A6791-818B-4BFA-A958-65D933FC7F2E} = {D707344C-5732-4DE6-92B5-16B0FCE6016F}
{748E8208-2140-40FB-BDD2-145F27C762BC} = {315E54AD-1A73-4CBD-8322-59C226A38724}
{69A8CB59-91D9-4550-B94B-803A9BF2CE1F} = {19AA42FA-3860-4D08-B5B0-9D26D751D5B8}
{F1059472-8C5E-4DE2-9ED9-27FCB0F5352B} = {664D406C-2F83-48F0-BFC3-408D5CB53C65}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3CB609D9-5D54-4C11-A371-DAAC8B74E430}
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ I would like this project to help you find simplified and effortless solutions.
- [x] Minimal hosting model
- [x] Migrate to .NET 7
- [x] HealthCheck
- [x] Websocket (SignalR)
- [ ] OpenTelemetry
- [ ] Add caching for EF Core
- [ ] Add caching for EF Core
- [ ] GRPC Error handling in interceptors
- [ ] MongoDB data provider

## Technologies used

[NET Core 6](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) : .NET Core, including ASP.NET Core
[NET Core 7](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) : .NET Core, including ASP.NET Core

[EntityFrameworkCore](https://github.com/dotnet/efcore): EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.

Expand Down Expand Up @@ -73,4 +75,6 @@ I would like this project to help you find simplified and effortless solutions.

[Scrutor](https://github.com/khellang/Scrutor): Assembly scanning and decoration extensions for Microsoft.Extensions.DependencyInjection.

[RestSharp](https://github.com/restsharp/RestSharp) RestSharp is a lightweight HTTP client library. It's a wrapper around HttpClient, not a full-fledged client on its own.
[RestSharp](https://github.com/restsharp/RestSharp): RestSharp is a lightweight HTTP client library. It's a wrapper around HttpClient, not a full-fledged client on its own.

[SignalR](https://github.com/dotnet/aspnetcore/tree/main/src/SignalR): ASP.NET Core SignalR is a library for ASP.NET Core developers that makes it incredibly simple to add real-time web functionality to your applications.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@

<ItemGroup>
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="6.1.0" />
<PackageReference Include="FluentResults" Version="3.15.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.2.2" />
<PackageReference Include="FluentResults" Version="3.15.1" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.4.0" />
<PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="Mapster.Async" Version="2.0.0" />
<PackageReference Include="Mapster.DependencyInjection" Version="1.0.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>


Expand All @@ -29,6 +30,19 @@

<ItemGroup>
<Generated Include="**\*.g.cs" />
<Generated Remove="obj\**" />
</ItemGroup>

<ItemGroup>
<Compile Remove="obj\**" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Remove="obj\**" />
</ItemGroup>

<ItemGroup>
<None Remove="obj\**" />
</ItemGroup>
<Target Name="CleanGenerated">
<Delete Files="@(Generated)" />
Expand Down
1 change: 1 addition & 0 deletions src/NKZSoft.Template.Common/NKZSoft.Template.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<ItemGroup>
<PackageReference Include="Ardalis.GuardClauses" Version="4.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion src/NKZSoft.Template.Domain/NKZSoft.Template.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="11.0.0" />
<PackageReference Include="MediatR" Version="11.1.0" />
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/NKZSoft.Template.Events/NKZSoft.Template.Events.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<PackageReference Include="MassTransit.Extensions.DependencyInjection" Version="7.3.1" />
<PackageReference Include="MassTransit.RabbitMQ" Version="8.0.8" />
<PackageReference Include="NKZSoft.Service.Configuration.MassTransit.RabbitMq" Version="1.0.1" />
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="6.1.0" />
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="6.0.2" />
<PackageReference Include="MediatR" Version="11.0.0" />
<PackageReference Include="MediatR" Version="11.1.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0">
Expand All @@ -28,11 +28,12 @@
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.0-rc.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
<PackageReference Include="Scrutor" Version="4.2.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />

</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ protected ResultResponse()
}

[ProtoMember(3)]
public bool IsSuccess { get; }
public bool IsSuccess { get; init; }


[ProtoMember(4)]
public ErrorResponse[] Errors { get; } = Array.Empty<ErrorResponse>();
public ErrorResponse[] Errors { get; init; } = Array.Empty<ErrorResponse>();
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -16,11 +16,12 @@

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.21.9" />
<PackageReference Include="protobuf-net" Version="3.1.22" />
<PackageReference Include="protobuf-net.Grpc.AspNetCore" Version="1.0.177" />
<PackageReference Include="protobuf-net.Grpc.AspNetCore.Reflection" Version="1.0.177" />
<PackageReference Include="protobuf-net.Reflection" Version="3.1.22" />
<PackageReference Include="protobuf-net" Version="3.1.25" />
<PackageReference Include="protobuf-net.Grpc.AspNetCore" Version="1.0.179" />
<PackageReference Include="protobuf-net.Grpc.AspNetCore.Reflection" Version="1.0.179" />
<PackageReference Include="protobuf-net.Reflection" Version="3.1.25" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.10.0" />
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -14,6 +14,7 @@
<PackageReference Include="HotChocolate.AspNetCore" Version="12.15.2" />
<PackageReference Include="HotChocolate.Data" Version="12.15.2" />
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="12.15.2" />
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/NKZSoft.Template.Presentation.REST/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
global using Microsoft.AspNetCore.Builder;
global using Microsoft.AspNetCore.Mvc.ModelBinding;
global using Microsoft.AspNetCore.Routing;
global using NKZSoft.Service.Configuration.Swagger;
global using NKZSoft.Template.Application.Common.Interfaces;
global using NKZSoft.Template.Application.Common.Paging;
global using NKZSoft.Template.Application.Models;
Expand All @@ -31,6 +30,7 @@
global using NKZSoft.Template.Application.TodoItems.Queries.Get;
global using NKZSoft.Template.Application.TodoItems.Queries.GetPage;
global using NKZSoft.Template.Common;
global using NKZSoft.Service.Configuration.Swagger;
global using Serilog;


Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,18 @@

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Version>1.1.2</Version>
<Version>1.1.4</Version>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1701;1702;1591</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1701;1702;1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentValidation.AspNetCore" Version="11.2.2" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.0" />
<PackageReference Include="NKZSoft.Service.Configuration.Logger" Version="1.0.1" />
<PackageReference Include="NKZSoft.Service.Configuration.Swagger" Version="1.0.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.25.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="6.0.3" />
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="6.0.2" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.0" />
<PackageReference Include="Xunit.Extensions.Ordering" Version="1.4.5" />
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
Expand All @@ -50,14 +23,5 @@
<ProjectReference Include="..\NKZSoft.Template.Persistence.PostgreSQL\NKZSoft.Template.Persistence.PostgreSQL.csproj" />
</ItemGroup>

<ItemGroup>
<None Remove="Properties\launchSettings.json" />
</ItemGroup>

<Target Name="Clean" AfterTargets="Clean"> <!-- common vars https://msdn.microsoft.com/en-us/library/c02as0cs.aspx?f=255&MSPPError=-2147217396 -->
<RemoveDir Directories="$(TargetDir)" /> <!-- bin -->
<RemoveDir Directories="$(ProjectDir)$(BaseIntermediateOutputPath)" /> <!-- obj -->
</Target>


</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace NKZSoft.Template.Presentation.SignalR.Extensions;

using Hubs;

public static class EndpointRouteBuilderExtension
{
/// <summary>
///
/// </summary>
/// <param name="endpointRouteBuilder"></param>
/// <returns></returns>
public static IEndpointRouteBuilder MapHubEndpoints(this IEndpointRouteBuilder endpointRouteBuilder)
{
endpointRouteBuilder.MapHub<ToDoItemHub>("/" + nameof(ToDoItemHub));
return endpointRouteBuilder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace NKZSoft.Template.Presentation.SignalR.Extensions;

public static class ServiceCollectionExtension
{
/// <summary>
///
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddSignalRPresentation(this IServiceCollection services)
{
services.AddSignalR();
return services;
}
}
8 changes: 8 additions & 0 deletions src/NKZSoft.Template.Presentation.SignalR/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Global using directives

global using System.Threading.Tasks;
global using Microsoft.AspNetCore.Builder;
global using Microsoft.AspNetCore.Routing;
global using Microsoft.AspNetCore.SignalR;
global using Microsoft.Extensions.DependencyInjection;
global using NKZSoft.Template.Application.Models;
10 changes: 10 additions & 0 deletions src/NKZSoft.Template.Presentation.SignalR/Hubs/ToDoItemHub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace NKZSoft.Template.Presentation.SignalR.Hubs;

public sealed class ToDoItemHub : Hub
{
public async Task<Guid> ToDoItemUpdated(ToDoItemDto toDoItemDto)
{
await Clients.All.SendAsync(nameof(ToDoItemUpdated), toDoItemDto);
return toDoItemDto.Id;
}
}
Loading

0 comments on commit 1202c13

Please sign in to comment.