Skip to content

Commit ca0e326

Browse files
committed
#15 continue to work on realtime notification
1 parent e9810a1 commit ca0e326

File tree

30 files changed

+258
-88
lines changed

30 files changed

+258
-88
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ BenchmarkDotNet.Artifacts/
5252
project.lock.json
5353
project.fragment.lock.json
5454
artifacts/
55-
**/Properties/launchSettings.json
55+
#**/Properties/launchSettings.json
5656

5757
# StyleCop
5858
StyleCopReport.xml

samples/Contracts/Events/ProjectCreated.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using MediatR;
21
using NetCoreKit.Domain;
32

43
namespace NetCoreKit.Samples.Contracts.Events
54
{
6-
public class ProjectCreated : EventBase, INotification
5+
public class ProjectCreated : EventBase
76
{
87
public ProjectCreated(string name)
98
{

samples/Contracts/Events/TaskCreated.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using MediatR;
21
using NetCoreKit.Domain;
32

43
namespace NetCoreKit.Samples.Contracts.Events
54
{
6-
public class TaskCreated : EventBase, INotification
5+
public class TaskCreated : EventBase
76
{
87
public TaskCreated(string title)
98
{

samples/Contracts/NetCoreKit.Samples.Contracts.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5+
<OutputType>Library</OutputType>
6+
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
7+
<LangVersion>latest</LangVersion>
58
</PropertyGroup>
69

7-
<ItemGroup>
8-
<PackageReference Include="MediatR" Version="5.1.0" />
9-
</ItemGroup>
10-
1110
<ItemGroup>
1211
<ProjectReference Include="..\..\src\NetCoreKit.Domain\NetCoreKit.Domain.csproj" />
1312
</ItemGroup>

samples/Notifier/EventsHostedService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public Task StopAsync(CancellationToken cancellationToken)
4242
private void OnStarted()
4343
{
4444
_logger.LogInformation("OnStarted has been called.");
45-
4645
_eventBus.Subscribe("project").Wait();
4746
}
4847

@@ -60,7 +59,7 @@ private void OnStopped()
6059
}
6160
}
6261

63-
public class ProjectCreatedSubscriber : INotificationHandler<ProjectCreated>
62+
/*public class ProjectCreatedSubscriber : INotificationHandler<ProjectCreated>
6463
{
6564
private readonly ILogger _logger;
6665
@@ -74,5 +73,5 @@ public Task Handle(ProjectCreated @event, CancellationToken cancellationToken)
7473
_logger.LogInformation($"@ Project Created Event -{@event.OccurredOn}-{@event.EventVersion}. Now I will do something cool in this worker...");
7574
return Task.FromResult(@event);
7675
}
77-
}
76+
}*/
7877
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:5002",
7+
"sslPort": 0
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"webnotifier": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development"
23+
},
24+
"applicationUrl": "http://localhost:5002"
25+
}
26+
}
27+
}

samples/SignalRNotifier/Services/Hubs/ProjectHub.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
using System;
21
using System.Threading;
32
using System.Threading.Tasks;
43
using MediatR;
54
using Microsoft.AspNetCore.SignalR;
65
using NetCoreKit.Domain;
7-
using NetCoreKit.Samples.Contracts.Events;
86

97
namespace NetCoreKit.Samples.SignalRNotifier.Services.Hubs
108
{
@@ -13,34 +11,32 @@ public class ProjectHub : Hub
1311
}
1412

1513
public class ProjectHostService : HostedService,
16-
INotificationHandler<ProjectCreated>,
17-
INotificationHandler<TaskCreated>
14+
INotificationHandler<Notifications.ProjectCreated>,
15+
INotificationHandler<Notifications.TaskCreated>
1816
{
1917
private readonly IEventBus _eventBus;
20-
private readonly IServiceProvider _resolver;
2118

22-
public ProjectHostService(IHubContext<ProjectHub> context, IServiceProvider resolver, IEventBus eventBus)
19+
public ProjectHostService(IHubContext<ProjectHub> context, IEventBus eventBus)
2320
{
24-
_resolver = resolver;
2521
_eventBus = eventBus;
2622
Clients = context.Clients;
2723
}
2824

2925
private IHubClients Clients { get; }
3026

31-
public async Task Handle(ProjectCreated @event, CancellationToken cancellationToken)
27+
public async Task Handle(Notifications.ProjectCreated notification, CancellationToken cancellationToken)
3228
{
33-
await Clients.All.SendAsync("projectCreatedNotify", @event, cancellationToken);
29+
await Clients.All.SendAsync("projectCreatedNotify", notification, cancellationToken);
3430
}
3531

36-
public async Task Handle(TaskCreated @event, CancellationToken cancellationToken)
32+
public async Task Handle(Notifications.TaskCreated notification, CancellationToken cancellationToken)
3733
{
38-
await Clients.All.SendAsync("taskAddedToProjectNotify", @event, cancellationToken);
34+
await Clients.All.SendAsync("taskAddedToProjectNotify", notification, cancellationToken);
3935
}
4036

4137
protected override Task ExecuteAsync(CancellationToken cancellationToken)
4238
{
43-
_eventBus.Subscribe("project");
39+
_eventBus.Subscribe("project").Wait(cancellationToken);
4440
return Task.CompletedTask;
4541
}
4642
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using MediatR;
3+
4+
namespace NetCoreKit.Samples.SignalRNotifier.Services.Notifications
5+
{
6+
public class ProjectCreated : INotification
7+
{
8+
public string Name { get; set; }
9+
public DateTime OccurredOn { get; set; }
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using MediatR;
3+
4+
namespace NetCoreKit.Samples.SignalRNotifier.Services.Notifications
5+
{
6+
public class TaskCreated : INotification
7+
{
8+
public string Title { get; set; }
9+
public DateTime OccurredOn { get; set; }
10+
}
11+
}

samples/SignalRNotifier/Services/Profiles/ProjectProfile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public class ProjectProfile : Profile
88
{
99
public ProjectProfile()
1010
{
11-
this.MapMySelf<ProjectCreated>();
12-
this.MapMySelf<TaskCreated>();
11+
this.MapToNotification<ProjectCreated, Notifications.ProjectCreated>();
12+
this.MapToNotification<TaskCreated, Notifications.TaskCreated>();
1313
}
1414
}
1515
}

0 commit comments

Comments
 (0)