Raain.Core
1.0.72
dotnet add package Raain.Core --version 1.0.72
NuGet\Install-Package Raain.Core -Version 1.0.72
<PackageReference Include="Raain.Core" Version="1.0.72" />
<PackageVersion Include="Raain.Core" Version="1.0.72" />
<PackageReference Include="Raain.Core" />
paket add Raain.Core --version 1.0.72
#r "nuget: Raain.Core, 1.0.72"
#:package Raain.Core@1.0.72
#addin nuget:?package=Raain.Core&version=1.0.72
#tool nuget:?package=Raain.Core&version=1.0.72
Raain.Core
Raain.Core is a shared .NET class library providing core functionalities including CORS, Extensions, Exception Handling, Firebase, SignalR, caching, and more.
Features
- Centralized extensions and helpers for .NET projects
- JWT authentication helpers
- Firebase integration
- SignalR helper methods
- CORS and API versioning support
- Health checks for PostgreSQL and Redis
- Logging using Serilog
- Compatible with
.NET 8.0(multi-targeting possible)
Getting Started
Prerequisites
- .NET SDK 8.0+ installed
- NuGet 6.0+ (comes with .NET SDK)
- Optional: PostgreSQL and Redis if using health checks
Example Usage
Configuring App Constants (RaainCoreConstOptions)
Your application can override default constants provided by the Raain.Core package at runtime.
1. Override Specific Values
Use RaainCoreConst.Configure to override only the properties you need:
using Raain.Core.Shared.Consts;
// Override some defaults in Program.cs
RaainCoreConst.Configure(opts =>
{
opts.AppName = "My Custom App";
opts.DefaultUsername = "customadmin@myapp.com";
opts.SwaggerApi = "My API";
opts.ApiKeyHeader = "X-My-Api-Key";
});
- Only the values you set will be replaced; all other defaults remain intact.
- Safe to call multiple times in different modules or initialization code.
2. Replace the Entire Options Object
You can create a full custom AppConstOptions instance and replace the defaults entirely:
var customOptions = new RaainCoreConstOptions
{
AppName = "Entirely New App",
DefaultUsername = "admin@newapp.com",
SwaggerApi = "New Swagger API",
CorsPolicyName = "CustomPolicy",
DefaultOrganizationMetadata = new JsonObject
{
["custom_key"] = "custom value"
}
};
// In Program.cs
RaainCoreConst.SetOptions(customOptions);
Or with class:
public class AppConst: RaainCoreConstOptions
{
// =======================
// App & System Defaults
// =======================
public override string AppName { get; set; } = "RAAIN";
... Other options
// In Program.cs
RaainCoreConst.SetOptions(new AppConst());
- This approach replaces all defaults, so make sure to set all required properties.
- Useful if you want to inject completely different defaults from your app configuration.
3. Accessing Configured Values
Anywhere in your application, you can read the configured values:
string appName = RaainCoreConst.Options.AppName;
string apiHeader = RaainCoreConst.Options.ApiKeyHeader;
string defaultUser = RaainCoreConst.Options.DefaultUsername;
JsonObject metadata = RaainCoreConst.Options.DefaultOrganizationMetadata;
Dependencies Setup
Raain.Core provides a consistent pattern to register services and middlewares across your application. The convention is:
- Dependency Injection (services):
Add[Package][Feature]() - Middleware / pipeline configuration:
Use[Package][Feature]()
Below is a summary of common modules and how to set them up.
Authentication & Authorization
// In ConfigureServices
services.AddRaainAuth(Configuration);
// In Configure / middleware pipeline
app.UseRaainAuth();
Session Management
services.AddRaainSession(Configuration);
app.UseRaainSession();
Data Access (Database / Repositories)
services.AddRaainDataAccess(Configuration);
Swagger / OpenAPI
services.AddRaainSwagger();
app.UseRaainSwagger();
Raain Notify (SignalR Notification)
// Configure AppConst options globally
AppConst.Configure(opts =>
{
opts.RaainNotifyHubPath = "/custom-notify";
opts.RaainNotifyNotifyAllHook = "CustomNotifyAll";
});
// Add Notify
builder.Services.AddRaainNotifyHub();
// Map hub if enabled
app.UseRaainNotifyHub(builder.Configuration);
- Sending notifications from server code:
using Microsoft.AspNetCore.SignalR;
using Raain.Core.RaainNotify;
public class NotificationService
{
private readonly IHubContext<RaainNotifyHub> _hub;
public NotificationService(IHubContext<RaainNotifyHub> hub)
{
_hub = hub;
}
public async Task NotifyEveryoneAsync(string message)
{
// Notify all clients
await _hub.Clients.All.SendAsync(AppConst.Options.RaainNotifyNotifyAllHook, message);
}
public async Task NotifyUserAsync(string userId, string message, ICachingService cache)
{
var key = CacheKey.Create(CacheGroupEnum.NotificationHub, userId);
var connections = await cache.GetRedisCacheAsync<HashSet<string>>(key);
if (connections != null)
{
foreach (var connId in connections)
await _hub.Clients.Client(connId).SendAsync(AppConst.Options.RaainNotifyNotifyAllHook, message);
}
}
}
Health Checks
services.AddRaainHealthChecks();
app.UseRaainHealthChecks();
// Or if not overriden RaainAppConstOptions.HealthCheckPath
app.UseRaainHealthCheck("/custom-health");
JSON Utilities / Serialization
services.AddRaainJson();
CORS policy
services.AddRaainCors();
services.UseRaainCors();
Rate Limit
services.AddRaainRateLimit();
services.UseRaainRateLimit();
Request Logging
services.AddRaainRequestLogging();
services.UseRaainRequestLogging();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Asp.Versioning.Mvc (>= 8.1.0)
- Asp.Versioning.Mvc.ApiExplorer (>= 8.1.0)
- AspNetCore.HealthChecks.NpgSql (>= 9.0.0)
- Dapper (>= 2.1.35)
- Google.Apis.Auth (>= 1.69.0)
- Google.Apis.Core (>= 1.69.0)
- Hangfire.MemoryStorage (>= 1.8.1.2)
- Konscious.Security.Cryptography.Argon2 (>= 1.3.1)
- libphonenumber-csharp (>= 9.0.19)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.14)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 9.0.2)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.14)
- Npgsql (>= 10.0.0)
- Refit (>= 8.0.0)
- Serilog (>= 4.0.0)
- Serilog.AspNetCore (>= 8.0.3)
- StackExchange.Redis (>= 2.8.31)
- Swashbuckle.AspNetCore (>= 8.0.0)
- Swashbuckle.AspNetCore.Annotations (>= 8.0.0)
- Swashbuckle.AspNetCore.SwaggerGen (>= 9.0.4)
- System.IdentityModel.Tokens.Jwt (>= 8.15.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.