Skip to content
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
7 changes: 4 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ builder
.AddMediatrWithBehaviors(AssemblyRegistry.ToArray())
.AddResilienceDefaultPipeline()
.MapDefaultTimeZone()
.AddRedis(KeyPrefix.AssemblyNamePrefix)
.AddDistributedSignalR("DistributedSignalR") // or .AddSignalR()
.AddDistributedFusionCache("redis://localhost:6379",
builder.Environment.GetShortEnvironmentName() + "_" + "app_name") // or .AddFusionCache(...)
.AddDistributedSignalR("redis://localhost:6379","app_name:") // or .AddSignalR()
.AddCors()
.AddHealthChecks();

Expand Down Expand Up @@ -621,14 +622,14 @@ This package includes various extensions and utilities to aid development:
retrieves DefaultTimeZone from `appsettings.json` and sets it as the default time zone.
- **UrlBuilder:** A utility for building URLs with query parameters.
- **Language ISO Code Helper:** Validate, query, and retrieve information about ISO language codes.
- **FusionCache Extensions:** Simplify the configuration of in memory or distributed caching with Redis.

### Related NuGet Packages

- **Pandatech.Crypto:** Provides cryptographic utilities.
- **Pandatech.FluentMinimalApiMapper:** Simplifies mapping in minimal APIs.
- **Pandatech.RegexBox:** A collection of useful regular expressions.
- **Pandatech.ResponseCrafter:** A utility for crafting consistent API responses.
- **Pandatech.DistributedCache:** A distributed cache provider for Redis.

## License

Expand Down
6 changes: 4 additions & 2 deletions Shared.Kernel.Demo/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using DistributedCache.Options;
using FluentMinimalApiMapper;
using Microsoft.AspNetCore.Mvc;
using SharedKernel.Demo2;
Expand Down Expand Up @@ -25,8 +26,9 @@
.AddControllers(AssemblyRegistry.ToArray())
.AddMediatrWithBehaviors(AssemblyRegistry.ToArray())
.AddResilienceDefaultPipeline()
// .AddRedis(KeyPrefix.AssemblyNamePrefix)
//.AddDistributedSignalR("DistributedSignalR") // or .AddSignalR()
.AddDistributedFusionCache("redis://localhost:6379",
builder.Environment.GetShortEnvironmentName() + "_" + "app_name") // or .AddFusionCache(...)
.AddDistributedSignalR("redis://localhost:6379","app_name:") // or .AddSignalR()
.MapDefaultTimeZone()
.AddCors()
.AddOutboundLoggingHandler()
Expand Down
42 changes: 42 additions & 0 deletions src/SharedKernel/Extensions/FusionCacheExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Caching.StackExchangeRedis;
using Microsoft.Extensions.DependencyInjection;
using ZiggyCreatures.Caching.Fusion;

namespace SharedKernel.Extensions;

public static class FusionCacheExtensions
{
private static IFusionCacheBuilder AddBaseFusionCache(WebApplicationBuilder builder, string instanceName)
{
return builder.Services
.AddFusionCache()
.WithRegisteredLogger()
.WithNeueccMessagePackSerializer()
.WithDefaultEntryOptions(new FusionCacheEntryOptions())
.WithCacheKeyPrefix(instanceName);
}


public static WebApplicationBuilder AddDistributedFusionCache(this WebApplicationBuilder builder,
string redisUrl,
string instanceName)
{
AddBaseFusionCache(builder, instanceName)
.WithDistributedCache(new RedisCache(new RedisCacheOptions
{
Configuration = redisUrl,
InstanceName = instanceName
}))
.WithStackExchangeRedisBackplane(o => o.Configuration = redisUrl)
.AsHybridCache();

return builder;
}

public static WebApplicationBuilder AddFusionCache(this WebApplicationBuilder builder, string instanceName)
{
AddBaseFusionCache(builder, instanceName);
return builder;
}
}
11 changes: 7 additions & 4 deletions src/SharedKernel/Extensions/OpenTelemetryExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@ public static WebApplicationBuilder AddOpenTelemetry(this WebApplicationBuilder
.WithMetrics(metrics =>
{
metrics.AddRuntimeInstrumentation()
.AddFusionCacheInstrumentation()
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddPrometheusExporter();
})
.WithTracing(tracing =>
{
tracing.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddEntityFrameworkCoreInstrumentation();
tracing
.AddFusionCacheInstrumentation()
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddEntityFrameworkCoreInstrumentation();
});

var otlpEnabled = !string.IsNullOrEmpty(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);

if (!otlpEnabled)
Expand Down
5 changes: 3 additions & 2 deletions src/SharedKernel/Extensions/SignalRExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ public static WebApplicationBuilder AddSignalR(this WebApplicationBuilder builde
}

public static WebApplicationBuilder AddDistributedSignalR(this WebApplicationBuilder builder,
string redisUrl,
string redisChannelName)
{
builder.AddSignalRWithFiltersAndMessagePack()
.AddStackExchangeRedis(builder.Configuration.GetRedisUrl(),
.AddStackExchangeRedis(redisUrl,
options =>
{
options.Configuration.ChannelPrefix = RedisChannel.Literal("FinHub:SignalR:");
options.Configuration.ChannelPrefix = RedisChannel.Literal(redisChannelName);
});


Expand Down
14 changes: 9 additions & 5 deletions src/SharedKernel/SharedKernel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Authors>Pandatech</Authors>
<Copyright>MIT</Copyright>
<Version>1.1.2</Version>
<Version>1.2.0</Version>
<PackageId>Pandatech.SharedKernel</PackageId>
<Title>Pandatech Shared Kernel Library</Title>
<PackageTags>Pandatech, shared kernel, library, OpenAPI, Swagger, utilities, scalar</PackageTags>
<Description>Pandatech.SharedKernel provides centralized configurations, utilities, and extensions for ASP.NET Core projects. For more information refere to readme.md document.</Description>
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-sharedkernel</RepositoryUrl>
<PackageReleaseNotes>Added dictinory extensions</PackageReleaseNotes>
<PackageReleaseNotes>Added fusion cache support</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -38,10 +38,11 @@
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.1" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="9.0.1" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.1.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.1" />
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.8.0-rc.1"/>
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.11.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.11.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.10.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta.12" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.10.0" />
Expand All @@ -52,9 +53,12 @@
<PackageReference Include="Pandatech.PandaVaultClient" Version="4.0.3" />
<PackageReference Include="Pandatech.RegexBox" Version="3.0.0" />
<PackageReference Include="Pandatech.ResponseCrafter" Version="5.1.5" />
<PackageReference Include="Scalar.AspNetCore" Version="2.0.2" />
<PackageReference Include="Scalar.AspNetCore" Version="2.0.4" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="7.2.0" />
<PackageReference Include="ZiggyCreatures.FusionCache.Backplane.StackExchangeRedis" Version="2.0.0" />
<PackageReference Include="ZiggyCreatures.FusionCache.OpenTelemetry" Version="2.0.0" />
<PackageReference Include="ZiggyCreatures.FusionCache.Serialization.NeueccMessagePack" Version="2.0.0" />
</ItemGroup>

</Project>