Tsutskiridze.Bloom.Core
1.0.7
dotnet add package Tsutskiridze.Bloom.Core --version 1.0.7
NuGet\Install-Package Tsutskiridze.Bloom.Core -Version 1.0.7
<PackageReference Include="Tsutskiridze.Bloom.Core" Version="1.0.7" />
paket add Tsutskiridze.Bloom.Core --version 1.0.7
#r "nuget: Tsutskiridze.Bloom.Core, 1.0.7"
// Install Tsutskiridze.Bloom.Core as a Cake Addin #addin nuget:?package=Tsutskiridze.Bloom.Core&version=1.0.7 // Install Tsutskiridze.Bloom.Core as a Cake Tool #tool nuget:?package=Tsutskiridze.Bloom.Core&version=1.0.7
Tsutskiridze.Bloom.Core
A powerful .NET package that provides essential functionality for Web API development, including CORS configuration, mail services, secret management, job scheduling, and more.
Installation
dotnet add package Tsutskiridze.Bloom.Core
Features
- 🔒 Secrets Management
- 📧 Mail Service
- ⏱️ Job Scheduling
- 🌐 CORS Configuration
- 🛡️ Error Handling
- 🔄 JSON Serialization
- 🎮 Base API Controller
- 💾 Caching (Memory/Redis)
Basic Setup
var builder = WebApplication.CreateBuilder(args);
// Add Bloom with default configuration
builder.Services.AddBloom();
var app = builder.Build();
// Use Bloom middleware and configurations
app.UseBloom();
app.Run();
Advanced Configuration
Custom Options
builder.Services.AddBloom(options =>
{
// Enable mail functionality
options.AddMail = true;
// Enable background jobs
options.AddJobs = true;
// Configure CORS
options.CorsOptions = new CorsConfOptions
{
UseDefaultPolicy = true
};
// Custom JSON serialization options
options.JsonSerializerOptions = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
WriteIndented = true
};
// Configure SMTP
options.SmtpOptions = new SmtpOptions
{
Host = "smtp.example.com",
Port = 587
//....
};
options.AddCache = true;
options.CacheOptions = new CacheOptions
{
Provider = CacheProvider.Redis, // or CacheProvider.Memory
ConnectionString = "your-redis-connection", // Required for Redis
DefaultExpiration = TimeSpan.FromMinutes(10),
EnableLogging = true
};
});
Secrets Management
The package uses a default secrets provider that reads from appsettings.json, but you can implement custom providers:
public class CustomSecretsProvider : ISecretsProvider
{
public string GetSecret(string key)
{
// Custom implementation
return "secret-value";
}
}
// Register custom provider
services.AddSecretsProvider<CustomSecretsProvider>();
// Set as active provider
options.ActiveSecretProvider = typeof(CustomSecretsProvider).ToString();
Mail Service
Create custom mail templates by inheriting from MailBase:
public class WelcomeMail : MailBase
{
private readonly string _username;
public WelcomeMail(string to, string username)
{
To = to;
Subject = "Welcome!";
_username = username;
}
protected override string HtmlBody()
{
return LoadTemplate("welcome.html", new Dictionary<string, string>
{
{ "username", _username }
});
}
}
// Send mail
await mailService.SendMail(new WelcomeMail("user@example.com", "John"));
Background Jobs
Create custom scheduled jobs:
public class DatabaseCleanupJob : IJob
{
public string Name => "Database Cleanup";
public string Cron => "0 0 * * *"; // Daily at midnight
public int Attempts => 3;
public async Task ExecuteAsync(CancellationToken cancellationToken)
{
// Cleanup logic
}
}
// Register job
services.AddJob<DatabaseCleanupJob>();
Required Configuration
The package expects the following configuration in appsettings.json:
{
"Smtp": {
"User": "your-smtp-user",
"Password": "your-smtp-password",
"Host": "smtp.host.com",
"Port": "587",
"EnableSsl": "True"
},
"Cors": {
"AllowedOrigins": "http://localhost:5173,http://localhost:5000"
}
}
you can override them also in AddBloom
Options
API Controller Usage
Inherit from ApiControllerBase to get standardized JSON responses:
public class UsersController : ApiControllerBase
{
[HttpGet]
public IActionResult GetUsers()
{
var users = // ... get users
return JsonResult(users, HttpStatusCode.OK);
}
}
Error Handling
The package includes built-in error handling middleware. Throw custom exceptions:
throw new CustomException(
"Resource not found",
HttpStatusCode.NotFound
);
// Or with multiple errors
throw new CustomException(
new Dictionary<string, string>
{
{ "email", "Invalid email format" },
{ "password", "Password too short" }
},
HttpStatusCode.BadRequest
);
Caching
The package supports both in-memory and Redis caching.
public class UserService
{
private readonly ICacheService _cache;
public async Task<User> GetUserAsync(int id)
{
return await _cache.GetOrSetAsync(
$"user:{id}",
async () => await _database.GetUserAsync(id),
TimeSpan.FromHours(1)
);
}
}
Contributing
Contributions are welcome! Please visit our GitHub repository for more information.
License
This project is licensed under the MIT License.
For more detailed information about specific components, please refer to the source code documentation and comments.
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. |
-
net8.0
- Azure.Core (>= 1.44.1)
- Cronos (>= 0.8.4)
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- StackExchange.Redis (>= 2.8.16)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release of the package