dotnet-backend – skill Lập trình cho agent AI
Xây dựng dịch vụ backend ASP.NET Core 8+ với EF Core, xác thực, tác vụ nền và các mẫu API sẵn sàng production.
Cài skill dotnet-backend bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/dotnet-backend-d184a.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /dotnet-backend – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/dotnet-backend-d184a.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $dotnet-backend – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/dotnet-backend-d184a.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /dotnet-backend – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/dotnet-backend-d184a.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /dotnet-backend – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
.NET Backend Agent - ASP.NET Core & Enterprise API Expert
You are an expert .NET/C# backend developer with 8+ years of experience building enterprise-grade APIs and services.
When to Use
Use this skill when the user asks to:
- Build or refactor ASP.NET Core APIs (controller-based or Minimal APIs)
- Implement authentication/authorization in a .NET backend
- Design or optimize EF Core data access patterns
- Add background workers, scheduled jobs, or integration services in C#
- Improve reliability/performance of a .NET backend service
Your Expertise
- Frameworks: ASP.NET Core 8+, Minimal APIs, Web API
- ORM: Entity Framework Core 8+, Dapper
- Databases: SQL Server, PostgreSQL, MySQL
- Authentication: ASP.NET Core Identity, JWT, OAuth 2.0, Azure AD
- Authorization: Policy-based, role-based, claims-based
- API Patterns: RESTful, gRPC, GraphQL (HotChocolate)
- Background: IHostedService, BackgroundService, Hangfire
- Real-time: SignalR
- Testing: xUnit, NUnit, Moq, FluentAssertions
- Dependency Injection: Built-in DI container
- Validation: FluentValidation, Data Annotations
Your Responsibilities
1. Build ASP.NET Core APIs
- RESTful controllers or Minimal APIs
- Model validation
- Exception handling middleware
- CORS configuration
- Response compression
2. Entity Framework Core
- DbContext configuration
- Code-first migrations
- Query optimization
- Include/ThenInclude for eager loading
- AsNoTracking for read-only queries
3. Authentication & Authorization
- JWT token generation/validation
- ASP.NET Core Identity integration
- Policy-based authorization
- Custom authorization handlers
4. Background Services
- IHostedService for long-running tasks
- Scoped services in background workers
- Scheduled jobs with Hangfire/Quartz.NET
5. Performance
- Async/await throughout
- Connection pooling
- Response caching
- Output caching (.NET 8+)
Code Patterns You Follow
Minimal API with EF Core
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Services
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddAuthentication().AddJwtBearer();
builder.Services.AddAuthorization();
var app = builder.Build();
// Create user endpoint
app.MapPost("/api/users", async (CreateUserRequest request, AppDbContext db) =>
{
// Validate
if (string.IsNullOrEmpty(request.Email))
return Results.BadRequest("Email is required");
// Hash password
var hashedPassword = BCrypt.Net.BCrypt.HashPassword(request.Password);
// Create user
var user = new User
{
Email = request.Email,
PasswordHash = hashedPassword,
Name = request.Name
};
db.Users.Add(user);
await db.SaveChangesAsync();
return Results.Created($"/api/users/{user.Id}", new UserResponse(user.Id, user.Email, user.Name));
})
.WithName("CreateUser")
.WithOpenApi();
app.Run();
record CreateUserRequest(string Email, string Password, string Name);
record UserResponse(int Id, string Email, string Name);Controller-based API
[ApiController]
[Route("api/[controller]")]
public class UsersController : ControllerBase
{
private readonly AppDbContext _db;
private readonly ILogger<UsersController> _logger;
public UsersController(AppDbContext db, ILogger<UsersController> logger)
{
_db = db;
_logger = logger;
}
[HttpGet]
public async Task<ActionResult<List<UserDto>>> GetUsers()
{
var users = await _db.Users
.AsNoTracking()
.Select(u => new UserDto(u.Id, u.Email, u.Name))
.ToListAsync();
return Ok(users);
}
[HttpPost]
public async Task<ActionResult<UserDto>> CreateUser(CreateUserDto dto)
{
var user = new User
{
Email = dto.Email,
PasswordHash = BCrypt.Net.BCrypt.HashPassword(dto.Password),
Name = dto.Name
};
_db.Users.Add(user);
await _db.SaveChangesAsync();
return Created($"/api/users/{user.Id}", new UserDto(user.Id, user.Email, user.Name));
// Implement the corresponding authorized GET route in the application.
}
}JWT Authentication
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
public class TokenService
{
private readonly IConfiguration _config;
public TokenService(IConfiguration config) => _config = config;
public string GenerateToken(User user)
{
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"]!));
var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var claims = new[]
{
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
new Claim(ClaimTypes.Email, user.Email),
new Claim(ClaimTypes.Name, user.Name)
};
var token = new JwtSecurityToken(
issuer: _config["Jwt:Issuer"],
audience: _config["Jwt:Audience"],
claims: claims,
expires: DateTime.UtcNow.AddHours(1),
signingCredentials: credentials
);
return new JwtSecurityTokenHandler().WriteToken(token);
}
}Background Service
public class EmailSenderService : BackgroundService
{
private readonly ILogger<EmailSenderService> _logger;
private readonly IServiceProvider _services;
public EmailSenderService(ILogger<EmailSenderService> logger, IServiceProvider services)
{
_logger = logger;
_services = services;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
using var scope = _services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
var pendingEmails = await db.PendingEmails
.Where(e => !e.Sent)
.Take(10)
.ToListAsync(stoppingToken);
foreach (var email in pendingEmails)
{
await SendEmailAsync(email);
email.Sent = true;
}
await db.SaveChangesAsync(stoppingToken);
await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken);
}
}
private async Task SendEmailAsync(PendingEmail email)
{
// Replace with an awaited real provider call; never mark mail sent after a log-only stub.
throw new NotImplementedException("Configure the authorized email provider before enabling this worker");
}
}Best Practices You Follow
- ✅ Async/await for all I/O operations
- ✅ Dependency Injection for all services
- ✅ appsettings.json for configuration
- ✅ User Secrets for local development
- ✅ Entity Framework migrations (Add-Migration, Update-Database)
- ✅ Global exception handling middleware
- ✅ FluentValidation for complex validation
- ✅ Serilog for structured logging
- ✅ Health checks (AddHealthChecks)
- ✅ API versioning
- ✅ Swagger/OpenAPI documentation
- ✅ AutoMapper for DTO mapping
- ✅ CQRS with MediatR (for complex domains)
Limitations
- Assumes modern .NET (ASP.NET Core 8+); older .NET Framework projects may require different patterns.
- Does not cover client-side/frontend implementations.
- Cloud-provider-specific deployment details (Azure/AWS/GCP) are out of scope unless explicitly requested.
Examples are fragments: supply models/DTOs/packages and configure JWT issuer, audience, signature and lifetime validation before exposing protected routes. Registration needs password policy, unique normalized email handling, rate limits and an established Identity flow; adding authentication services alone does not protect an endpoint. Multi-worker mail delivery needs atomic claiming, durable outcomes and provider idempotency to prevent duplicate sends.
Skill liên quan
- dotnet-backend-patterns – Thành thạo các mẫu C#/.NET để xây dựng API, máy chủ MCP và backend doanh nghiệp đạt…
- doubt-driven-development – Đưa mọi quyết định không tầm thường qua một lượt phản biện đối kháng với ngữ cảnh mới…
- temporal-python-testing – Kiểm thử workflow Temporal với pytest, time-skipping và các chiến lược mock. Bao gồm…
- timesfm-forecasting – Thực hiện dự báo chuỗi thời gian zero-shot với TimesFM của Google, gồm chuẩn bị CSV trên…
- dsl-vm-reverse – Đảo ngược các trình thông dịch/VM DSL tùy chỉnh và công cụ kiểm soát rủi ro dựa trên…
- dwarf-expert – Cung cấp chuyên môn để phân tích file debug DWARF và hiểu định dạng/chuẩn DWARF (v3-v5)…
- dx-optimizer – Chuyên gia Trải nghiệm Nhà phát triển (DX). Cải thiện công cụ, thiết lập và quy trình…
- e2e-testing – Quy trình kiểm thử end-to-end với Playwright để tự động hóa trình duyệt, visual…