Skip to content

Commit 67e87bf

Browse files
authored
Merge pull request #86 from PandaTechAM/development
nuget updates, request/response enhancement, perf boosts
2 parents 74a8edf + 029fa46 commit 67e87bf

24 files changed

+1245
-1192
lines changed

SharedKernel.Demo/LoggingTestEndpoints.cs

Lines changed: 221 additions & 115 deletions
Large diffs are not rendered by default.

SharedKernel.Demo/MessageHub.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Microsoft.AspNetCore.SignalR;
22
using ResponseCrafter.ExceptionHandlers.SignalR;
3-
using System.Threading;
43

54
namespace SharedKernel.Demo;
65

SharedKernel.Demo/SharedKernel.Demo.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
<ItemGroup>
1010
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" Version="9.0.0"/>
11-
<PackageReference Include="MassTransit.RabbitMQ" Version="8.5.7" />
12-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.1" />
13-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.1" />
11+
<PackageReference Include="MassTransit.RabbitMQ" Version="[8.5.7]" />
12+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.2" />
1414
</ItemGroup>
1515

1616
<ItemGroup>

src/SharedKernel/Extensions/DictionaryExtensions.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,31 @@ namespace SharedKernel.Extensions;
55

66
public static class DictionaryExtensions
77
{
8-
public static TValue? GetOrAdd<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, TValue? value)
9-
where TKey : notnull
8+
extension<TKey, TValue>(Dictionary<TKey, TValue> dict) where TKey : notnull
109
{
11-
ref var val = ref CollectionsMarshal.GetValueRefOrAddDefault(dict, key, out var exists);
12-
13-
if (exists)
10+
public TValue? GetOrAdd(TKey key, TValue? value)
1411
{
12+
ref var val = ref CollectionsMarshal.GetValueRefOrAddDefault(dict, key, out var exists);
13+
14+
if (exists)
15+
{
16+
return val;
17+
}
18+
19+
val = value;
1520
return val;
1621
}
1722

18-
val = value;
19-
return val;
20-
}
21-
22-
public static bool TryUpdate<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, TValue value)
23-
where TKey : notnull
24-
{
25-
ref var val = ref CollectionsMarshal.GetValueRefOrNullRef(dict, key);
26-
if (Unsafe.IsNullRef(ref val))
23+
public bool TryUpdate(TKey key, TValue value)
2724
{
28-
return false;
29-
}
25+
ref var val = ref CollectionsMarshal.GetValueRefOrNullRef(dict, key);
26+
if (Unsafe.IsNullRef(ref val))
27+
{
28+
return false;
29+
}
3030

31-
val = value;
32-
return true;
31+
val = value;
32+
return true;
33+
}
3334
}
3435
}

src/SharedKernel/Extensions/HostEnvironmentExtensions.cs

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,61 @@ namespace SharedKernel.Extensions;
44

55
public static class HostEnvironmentExtensions
66
{
7-
public static bool IsQa(this IHostEnvironment hostEnvironment)
7+
extension(IHostEnvironment hostEnvironment)
88
{
9-
ArgumentNullException.ThrowIfNull(hostEnvironment);
10-
11-
return hostEnvironment.IsEnvironment("QA");
12-
}
13-
14-
public static bool IsLocal(this IHostEnvironment hostEnvironment)
15-
{
16-
ArgumentNullException.ThrowIfNull(hostEnvironment);
17-
18-
return hostEnvironment.IsEnvironment("Local");
19-
}
20-
21-
public static bool IsLocalOrDevelopment(this IHostEnvironment hostEnvironment)
22-
{
23-
ArgumentNullException.ThrowIfNull(hostEnvironment);
24-
25-
return hostEnvironment.IsLocal() || hostEnvironment.IsDevelopment();
26-
}
27-
28-
public static bool IsLocalOrDevelopmentOrQa(this IHostEnvironment hostEnvironment)
29-
{
30-
ArgumentNullException.ThrowIfNull(hostEnvironment);
31-
32-
return hostEnvironment.IsLocal() || hostEnvironment.IsDevelopment() || hostEnvironment.IsQa();
33-
}
9+
public bool IsQa()
10+
{
11+
ArgumentNullException.ThrowIfNull(hostEnvironment);
3412

35-
public static string GetShortEnvironmentName(this IHostEnvironment environment)
36-
{
37-
ArgumentNullException.ThrowIfNull(environment);
13+
return hostEnvironment.IsEnvironment("QA");
14+
}
3815

39-
if (environment.IsLocal())
16+
public bool IsLocal()
4017
{
41-
return "local";
18+
ArgumentNullException.ThrowIfNull(hostEnvironment);
19+
20+
return hostEnvironment.IsEnvironment("Local");
4221
}
4322

44-
if (environment.IsDevelopment())
23+
public bool IsLocalOrDevelopment()
4524
{
46-
return "dev";
25+
ArgumentNullException.ThrowIfNull(hostEnvironment);
26+
27+
return hostEnvironment.IsLocal() || hostEnvironment.IsDevelopment();
4728
}
4829

49-
if (environment.IsQa())
30+
public bool IsLocalOrDevelopmentOrQa()
5031
{
51-
return "qa";
32+
ArgumentNullException.ThrowIfNull(hostEnvironment);
33+
34+
return hostEnvironment.IsLocal() || hostEnvironment.IsDevelopment() || hostEnvironment.IsQa();
5235
}
5336

54-
if (environment.IsStaging())
37+
public string GetShortEnvironmentName()
5538
{
56-
return "staging";
57-
}
39+
ArgumentNullException.ThrowIfNull(hostEnvironment);
40+
41+
if (hostEnvironment.IsLocal())
42+
{
43+
return "local";
44+
}
45+
46+
if (hostEnvironment.IsDevelopment())
47+
{
48+
return "dev";
49+
}
5850

59-
return "";
51+
if (hostEnvironment.IsQa())
52+
{
53+
return "qa";
54+
}
55+
56+
if (hostEnvironment.IsStaging())
57+
{
58+
return "staging";
59+
}
60+
61+
return "";
62+
}
6063
}
6164
}

src/SharedKernel/Extensions/SignalRExtensions.cs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,41 @@ namespace SharedKernel.Extensions;
1111

1212
public static class SignalRExtensions
1313
{
14-
public static WebApplicationBuilder AddSignalR(this WebApplicationBuilder builder)
14+
extension(WebApplicationBuilder builder)
1515
{
16-
builder.AddSignalRWithFiltersAndMessagePack();
17-
return builder;
18-
}
16+
public WebApplicationBuilder AddSignalR()
17+
{
18+
builder.AddSignalRWithFiltersAndMessagePack();
19+
return builder;
20+
}
1921

20-
public static WebApplicationBuilder AddDistributedSignalR(this WebApplicationBuilder builder,
21-
string redisUrl,
22-
string redisChannelName)
23-
{
24-
builder.AddSignalRWithFiltersAndMessagePack()
25-
.AddStackExchangeRedis(redisUrl,
26-
options =>
27-
{
28-
options.Configuration.ChannelPrefix = RedisChannel.Literal(redisChannelName);
29-
});
22+
public WebApplicationBuilder AddDistributedSignalR(string redisUrl,
23+
string redisChannelName)
24+
{
25+
builder.AddSignalRWithFiltersAndMessagePack()
26+
.AddStackExchangeRedis(redisUrl,
27+
options =>
28+
{
29+
options.Configuration.ChannelPrefix = RedisChannel.Literal(redisChannelName);
30+
});
3031

3132

32-
return builder;
33-
}
33+
return builder;
34+
}
3435

35-
private static ISignalRServerBuilder AddSignalRWithFiltersAndMessagePack(this WebApplicationBuilder builder)
36-
{
37-
return builder.Services
38-
.AddSignalR(o =>
39-
{
40-
if (Log.Logger.IsEnabled(LogEventLevel.Information))
36+
private ISignalRServerBuilder AddSignalRWithFiltersAndMessagePack()
37+
{
38+
return builder.Services
39+
.AddSignalR(o =>
4140
{
42-
o.AddFilter<SignalRLoggingHubFilter>();
43-
}
41+
if (Log.Logger.IsEnabled(LogEventLevel.Information))
42+
{
43+
o.AddFilter<SignalRLoggingHubFilter>();
44+
}
4445

45-
o.AddFilter<SignalRExceptionFilter>();
46-
})
47-
.AddMessagePackProtocol();
46+
o.AddFilter<SignalRExceptionFilter>();
47+
})
48+
.AddMessagePackProtocol();
49+
}
4850
}
4951
}

src/SharedKernel/JsonConverters/EnumConverterFactory.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Text.Json;
1+
using System.Text.Json;
62
using System.Text.Json.Serialization;
7-
using System.Threading.Tasks;
83

94
namespace SharedKernel.JsonConverters;
105

@@ -21,12 +16,12 @@ public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializer
2116
var underlyingType = Nullable.GetUnderlyingType(typeToConvert);
2217
if (underlyingType != null) // It's a nullable enum
2318
{
24-
Type converterType = typeof(NullableEnumConverter<>).MakeGenericType(underlyingType);
19+
var converterType = typeof(NullableEnumConverter<>).MakeGenericType(underlyingType);
2520
return (JsonConverter)Activator.CreateInstance(converterType)!;
2621
}
2722
else // Non-nullable enum
2823
{
29-
Type converterType = typeof(NonNullableEnumConverter<>).MakeGenericType(typeToConvert);
24+
var converterType = typeof(NonNullableEnumConverter<>).MakeGenericType(typeToConvert);
3025
return (JsonConverter)Activator.CreateInstance(converterType)!;
3126
}
3227
}

0 commit comments

Comments
 (0)