A comprehensive framework library for .NET 8 Web API projects providing base classes, extensions, and utilities for rapid development.
- Entity Base Classes - Ready-to-use base entities with audit fields (CreatedAt, UpdatedAt, DeletedAt)
- Repository Pattern - Generic repository base classes with SqlSugar integration
- Transaction Helpers - Simplified database transaction management
- Result Wrappers - Standardized API response models (ApiResult, SuccessfulResult, FailedResult)
- Task Extensions - Safe fire-and-forget execution with exception handling
- DateTime Extensions - Unix timestamp conversions and timezone utilities
- Service Collection Extensions - DI container configuration helpers
- Enum Extensions - Enhanced enum operations
- Global Exception Handling - Centralized exception management
- JWT Authentication Helpers - Token generation and validation utilities
- Database Connection Management - Multi-database support (MySQL, SQL Server, PostgreSQL, Oracle)
- Text Encryption Helpers - Secure data encryption utilities
- Gravatar Integration - User avatar generation
Install-Package Shukebeta.Api.Frameworkdotnet add package Shukebeta.Api.Framework<PackageReference Include="Shukebeta.Api.Framework" Version="1.0.1" />// Simple entity with audit fields
public class User : EntityBase
{
public string Name { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
}
// Entity with admin audit fields
public class Product : AdminEntityBase
{
public string Name { get; set; } = string.Empty;
public decimal Price { get; set; }
// Inherits: CreatedAt, UpdatedAt, DeletedAt, CreateBy, UpdateBy
}public class UserRepository(ISqlSugarClient db) : RepositoryBase<User>(db)
{
public async Task<User?> GetByEmailAsync(string email)
{
return await GetFirstOrDefaultAsync(u => u.Email == email);
}
public async Task<PageData<User>> GetUsersPagedAsync(int pageNumber, int pageSize)
{
return await GetPagedAsync(pageNumber, pageSize, u => u.CreatedAt, false);
}
}[ApiController]
[Route("api/[controller]")]
public class UsersController(UserRepository userRepository) : ControllerBase
{
[HttpGet]
public async Task<ApiResult<PageData<User>>> GetUsers(int page = 1, int size = 10)
{
var users = await userRepository.GetUsersPagedAsync(page, size);
return ApiResult<PageData<User>>.Success(users);
}
[HttpPost]
public async Task<ApiResult<User>> CreateUser(CreateUserRequest request)
{
var user = new User { Name = request.Name, Email = request.Email };
var userId = await userRepository.InsertReturnIdentityAsync(user);
user.Id = userId;
return ApiResult<User>.Success(user);
}
}public class NotificationService(
IEnumerable<INotificationProvider> providers,
ILogger<NotificationService> logger)
{
public void SendNotifications(string message)
{
// Safe fire-and-forget with automatic exception handling
TaskExtensions.SafeFireAndForgetBatch(
providers,
async provider => await provider.SendAsync(message),
logger,
"Failed to send notification"
);
}
}public class OrderService(ISqlSugarClient db, ILogger<OrderService> logger)
{
public async Task<Order> CreateOrderAsync(CreateOrderRequest request)
{
return await TransactionHelper.ExecuteInTransactionAsync(db, async () =>
{
// All operations within a single transaction
var order = new Order { /* ... */ };
var orderId = await orderRepository.InsertReturnIdentityAsync(order);
foreach (var item in request.Items)
{
await orderItemRepository.InsertAsync(new OrderItem
{
OrderId = orderId,
/* ... */
});
}
return order;
}, logger);
}
}// In Program.cs
builder.Services.Configure<DatabaseConnectionOptions>(
builder.Configuration.GetSection("Database"));
builder.Services.AddSqlSugar(options =>
{
options.ConnectionString = connectionString;
options.DbType = DatabaseType.MySql;
});{
"Database": {
"ConnectionString": "Server=localhost;Database=MyApp;Uid=user;Pwd=password;",
"DbType": "MySql"
}
}{
"Jwt": {
"Key": "your-secret-key-here",
"Issuer": "your-app-name",
"Audience": "your-audience",
"ExpireMinutes": 60
}
}The framework includes comprehensive unit tests covering all major components:
# Run tests
dotnet test
# Run with coverage
dotnet test --collect:"XPlat Code Coverage"Test Coverage:
- β Entity base classes
- β Extension methods (DateTime, Task, Enum)
- β Exception handling
- β Encryption utilities
- β Unix timestamp helpers
Base entity with standard audit fields:
Id(long) - Primary keyCreatedAt(long) - Unix timestampUpdatedAt(long?) - Unix timestampDeletedAt(long?) - Unix timestamp for soft delete
Generic repository with common operations:
GetAsync(id)- Get by primary keyGetFirstOrDefaultAsync(predicate)- Get first matching entityGetPagedAsync(page, size, orderBy, desc)- Paginated resultsInsertAsync(entity)- Insert entityUpdateAsync(entity)- Update entityDeleteAsync(entity)- Delete entity
Standardized API response:
Success(data, message?)- Success responseError(errorCode, message)- Error responseSuccessful(bool) - Success indicatorData(T) - Response dataMessage(string) - Response message
- Remove local
Api.Frameworkproject references - Install the NuGet package:
dotnet add package Shukebeta.Api.Framework - Update namespace imports from
Api.Framework.*toApi.Framework.*(no change needed) - All existing code should work without modifications
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Ensure all tests pass:
dotnet test - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- NuGet Package: https://www.nuget.org/packages/Shukebeta.Api.Framework/
- GitHub Repository: https://github.com/shukebeta/Api.Framework
- Issues: https://github.com/shukebeta/Api.Framework/issues
See CHANGELOG.md for a complete list of changes and version history.
Made with β€οΈ for .NET developers by @shukebeta