PowerCSharp.Extensions.AspNetCore
1.0.0
dotnet add package PowerCSharp.Extensions.AspNetCore --version 1.0.0
NuGet\Install-Package PowerCSharp.Extensions.AspNetCore -Version 1.0.0
<PackageReference Include="PowerCSharp.Extensions.AspNetCore" Version="1.0.0" />
<PackageVersion Include="PowerCSharp.Extensions.AspNetCore" Version="1.0.0" />
<PackageReference Include="PowerCSharp.Extensions.AspNetCore" />
paket add PowerCSharp.Extensions.AspNetCore --version 1.0.0
#r "nuget: PowerCSharp.Extensions.AspNetCore, 1.0.0"
#:package PowerCSharp.Extensions.AspNetCore@1.0.0
#addin nuget:?package=PowerCSharp.Extensions.AspNetCore&version=1.0.0
#tool nuget:?package=PowerCSharp.Extensions.AspNetCore&version=1.0.0
PowerCSharp.Extensions.AspNetCore
ASP.NET Core specific extension methods for modern web development. This package provides specialized extensions for configuration management, web utilities, and HTTP operations that require ASP.NET Core dependencies.
Recent Improvements (v0.3.0):
- Package Separation: Extracted from PowerCSharp.Extensions for cleaner dependency management
- Enhanced Performance: Optimized HTTP operations and configuration handling
- Better Integration: Improved ASP.NET Core dependency injection support
- Updated Dependencies: All Microsoft.Extensions packages updated to .NET 8.0 compatible versions
๐ฆ Package Information
- Package ID:
PowerCSharp.Extensions.AspNetCore - Version: 0.3.0
- Target Frameworks: .NET 8.0
- Dependencies:
PowerCSharp.Core(for shared interfaces)Microsoft.AspNetCore.WebUtilitiesv8.0.8 (for URL query string manipulation)Microsoft.Extensions.Configuration.Abstractionsv8.0.0 (for configuration support)Microsoft.Extensions.Configuration.Binderv8.0.0 (for configuration binding)Microsoft.Extensions.DependencyInjectionv8.0.0 (for dependency injection)Microsoft.Extensions.Optionsv8.0.0 (for options pattern)
๐ Installation
dotnet add package PowerCSharp.Extensions.AspNetCore
๐ Extension Categories
โ๏ธ Configuration Extensions
Simplified configuration binding and options management for ASP.NET Core applications.
using PowerCSharp.Extensions.AspNetCore;
using Microsoft.Extensions.Configuration;
var configuration = new ConfigurationBuilder().Build();
var options = configuration.GetOptions<MyAppOptions>("MyApp"); // Reads from "MyApp" section
Features:
- Type-safe configuration binding with automatic validation
- Section-based configuration loading
- Null-safe operations with meaningful error messages
- IAppOptions interface integration for standardized options
๐ HTTP & Network Extensions
Enhanced HTTP operations for web applications including request cloning and URL manipulation.
using PowerCSharp.Extensions.AspNetCore;
using System.Net.Http;
// HTTP Status Code utilities
HttpStatusCode status = HttpStatusCode.OK;
bool success = status.IsSuccessful(); // true
bool clientError = status.IsClientError(); // false
bool serverError = status.IsServerError(); // false
bool isRedirect = status.IsRedirect(); // false
// URI manipulation with query string support
Uri uri = new Uri("https://example.com");
Uri withParam = uri.AddParameter("search", "test"); // https://example.com?search=test
Uri multipleParams = uri.AddParameter("page", "1").AddParameter("size", "10");
// HTTP Request cloning for retry scenarios
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.example.com");
var clonedRequest = request.Clone();
var clonedAsync = await request.CloneAsync();
Features:
- Request cloning for retry patterns and logging
- Query string manipulation with proper encoding
- HTTP status code categorization utilities
- Async/await support for all operations
๐ฏ Key Features
โ ASP.NET Core Integration
Built specifically for ASP.NET Core applications with proper dependency injection support and middleware compatibility.
โ Thread Safety
All extension methods are designed to be thread-safe when used with immutable data structures.
โ Null Safety
Comprehensive null checking and graceful error handling throughout.
โ Performance Optimized
Methods are optimized for performance with minimal allocations and efficient algorithms.
โ Modern .NET Only
Leverages the latest .NET 8.0 features and ASP.NET Core capabilities.
๐ Dependencies
PowerCSharp.Extensions.AspNetCore depends on:
- PowerCSharp.Core - Shared interfaces and base functionality
- Microsoft.AspNetCore.WebUtilities v8.0.8 - URL query string manipulation and web utilities
- Microsoft.Extensions.Configuration.Abstractions v8.0.0 - Configuration support
- Microsoft.Extensions.Configuration.Binder v8.0.0 - Configuration binding
- Microsoft.Extensions.DependencyInjection v8.0.0 - Dependency injection support
- Microsoft.Extensions.Options v8.0.0 - Options pattern support
๐ง Recent Updates (v0.3.0)
- Package Compatibility: Resolved NuGet package compatibility issues for .NET 8.0
- Dependency Updates: Updated all Microsoft.Extensions packages to v8.0.x for full .NET 8.0 compatibility
- Build Improvements: Enhanced package generation and symbol packages
๐งช Testing
PowerCSharp.Extensions.AspNetCore includes comprehensive unit tests. Run tests with:
dotnet test src/PowerCSharp.Extensions.AspNetCore.Tests
๐ Documentation
- Main PowerCSharp Documentation - Complete ecosystem overview
- PowerCSharp.Core - Core interfaces and architecture
- PowerCSharp.Extensions - Cross-platform extensions
- Detailed API Documentation - Complete API reference
- Contributing Guide - How to contribute
- Workflow Documentation - Development workflow
๐ก Usage Examples
ASP.NET Core Web API Scenario
using PowerCSharp.Extensions.AspNetCore;
using Microsoft.AspNetCore.Mvc;
[ApiController]
public class UsersController : ControllerBase
{
private readonly IConfiguration _configuration;
public UsersController(IConfiguration configuration)
{
_configuration = configuration;
}
[HttpGet]
public IActionResult GetUsers([FromQuery] string search = "", [FromQuery] int page = 1)
{
// Load configuration
var apiSettings = _configuration.GetOptions<ApiSettings>("ApiSettings");
// Build URL with parameters
var baseUrl = new Uri(apiSettings.BaseUrl);
var requestUrl = baseUrl
.AddParameter("search", search)
.AddParameter("page", page.ToString())
.AddParameter("size", apiSettings.DefaultPageSize.ToString());
return Ok(new { RequestUrl = requestUrl.ToString() });
}
}
HTTP Client with Retry Logic
using PowerCSharp.Extensions.AspNetCore;
using System.Net.Http;
public class ResilientHttpClient
{
private readonly HttpClient _httpClient;
public ResilientHttpClient(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<HttpResponseMessage> ExecuteWithRetryAsync(HttpRequestMessage request, int maxRetries = 3)
{
HttpResponseMessage? response = null;
for (int attempt = 1; attempt <= maxRetries; attempt++)
{
try
{
// Clone request for each attempt (HttpRequestMessage can only be sent once)
var clonedRequest = request.Clone();
response = await _httpClient.SendAsync(clonedRequest);
if (response.IsSuccessStatusCode || !ShouldRetry(response.StatusCode))
{
return response;
}
await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, attempt)));
}
catch
{
if (attempt == maxRetries) throw;
}
}
return response ?? throw new InvalidOperationException("Failed to execute request after retries");
}
private static bool ShouldRetry(HttpStatusCode statusCode)
{
return statusCode.IsServerError() || statusCode == HttpStatusCode.RequestTimeout;
}
}
Configuration Management
using PowerCSharp.Extensions.AspNetCore;
public class AppSettings
{
public string ApiUrl { get; set; } = "";
public int MaxRetries { get; set; } = 3;
public bool EnableLogging { get; set; } = true;
}
public class Startup
{
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
// Load and validate settings
var settings = configuration.GetOptions<AppSettings>("AppSettings");
// Configure services based on settings
services.Configure<AppSettings>(configuration.GetSection("AppSettings"));
if (settings.EnableLogging)
{
services.AddLogging();
}
}
}
๐๏ธ Architecture
PowerCSharp.Extensions.AspNetCore follows the same architectural principles as the PowerCSharp ecosystem:
- Centralized interfaces from PowerCSharp.Core
- Consistent namespace organization with
PowerCSharp.Extensions.AspNetCore.* - Clear separation of concerns between web-specific and cross-platform functionality
- Dependency injection friendly design
๐ค Contributing
Contributions are welcome! Please read our Contributing Guidelines for details.
Development Setup
- Clone the repository
- Navigate to PowerCSharp.Extensions.AspNetCore project
- Restore dependencies:
dotnet restore - Run tests:
dotnet test - Make your changes
- Add tests for new functionality
- Submit a Pull Request
Adding New Extensions
When adding new ASP.NET Core specific extension methods:
- Choose the right category - Place extensions in the appropriate folder (Configuration, Net, etc.)
- Follow naming conventions - Use descriptive, PascalCase method names
- Add XML documentation - Include comprehensive XML docs
- Write unit tests - Cover all scenarios and edge cases
- Update documentation - Add to API documentation
- Consider cross-platform compatibility - If functionality could work outside ASP.NET Core, consider adding to PowerCSharp.Extensions instead
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Related Packages
- PowerCSharp.Core - Core interfaces and architecture
- PowerCSharp.Extensions - Cross-platform extension methods
- PowerCSharp.Utilities - Utility classes and helpers
- PowerCSharp.Helpers - Specialized helper classes
๐ Support
- ๐ Report Issues
- ๐ก Feature Requests
- ๐ง Email Support
PowerCSharp.Extensions.AspNetCore - Making ASP.NET Core development more powerful, one extension at a time! ๐
| 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
- Ben.Demystifier (>= 0.4.1)
- Microsoft.AspNetCore.WebUtilities (>= 8.0.8)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- PowerCSharp.Core (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.