Skip to content

Commit

Permalink
feat: add signalR
Browse files Browse the repository at this point in the history
  • Loading branch information
phamhongphuc1403 committed Jun 1, 2024
1 parent 18c1695 commit 8163b4f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
7 changes: 7 additions & 0 deletions BuildingBlocks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{CFE5A713-D
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructure", "Infrastructure", "{9BFF2EA3-E081-4A2B-8297-A028DDD73E4A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuildingBlock.Infrastructure.SignalR", "Infrastructure\BuildingBlock.Infrastructure.SignalR\BuildingBlock.Infrastructure.SignalR.csproj", "{6DED74C6-3D90-409E-8D97-91CD5522ECA2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -66,6 +68,10 @@ Global
{C9891FE2-E5C6-4773-BCA0-919FDCC132D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9891FE2-E5C6-4773-BCA0-919FDCC132D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9891FE2-E5C6-4773-BCA0-919FDCC132D2}.Release|Any CPU.Build.0 = Release|Any CPU
{6DED74C6-3D90-409E-8D97-91CD5522ECA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6DED74C6-3D90-409E-8D97-91CD5522ECA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DED74C6-3D90-409E-8D97-91CD5522ECA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DED74C6-3D90-409E-8D97-91CD5522ECA2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{0C2BE5AF-98DD-4E1D-A385-98E6B2D8A3A2} = {37ABC0F6-39B9-4057-955A-BA2CFDB64811}
Expand All @@ -77,5 +83,6 @@ Global
{4E1A0628-01F4-4876-B943-AC9FAFB19238} = {9BFF2EA3-E081-4A2B-8297-A028DDD73E4A}
{2667E7B6-8451-4842-9CC5-0663C8CAE5F4} = {9BFF2EA3-E081-4A2B-8297-A028DDD73E4A}
{C9891FE2-E5C6-4773-BCA0-919FDCC132D2} = {9BFF2EA3-E081-4A2B-8297-A028DDD73E4A}
{6DED74C6-3D90-409E-8D97-91CD5522ECA2} = {9BFF2EA3-E081-4A2B-8297-A028DDD73E4A}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>Phuc1403.BuildingBlock.Infrastructure.SignalR</PackageId>
<Version>$([System.DateTime]::Now.ToString("yyyy.MM.dd.HHmm"))</Version>
<Authors>Phuc Pham Hong</Authors>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions Infrastructure/BuildingBlock.Infrastructure.SignalR/Hub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.SignalR;

namespace BuildingBlock.Infrastructure.SignalR;

public class Hub : Microsoft.AspNetCore.SignalR.Hub
{
public override async Task OnConnectedAsync()
{
await Clients.All.SendAsync("ReceiveMessage", $"{Context.ConnectionId} joined the chat");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.Extensions.DependencyInjection;

namespace BuildingBlock.Presentation.API.Extensions;

public static class RealTimeExtension
{
public static IServiceCollection AddRealTime(this IServiceCollection services)
{
services.AddSignalR();

return services;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.SignalR;

namespace BuildingBlock.Presentation.API.Middlewares;

public static class RealTimeMiddleware
{
public static IEndpointRouteBuilder UseRealTime(this IEndpointRouteBuilder app)
{
app.MapHub<Hub>("hub");

return app;
}
}

0 comments on commit 8163b4f

Please sign in to comment.