Logo Aspnet Core

Aspnet Core

Cộng đồng
alpham8
aspnet-core

Use when developing ASP.NET Core applications - Minimal APIs, dependency injection, middleware, Entity Framework Core, SignalR, authentication (JWT/Identity), configuration, health checks, caching, MassTransit, rate limiting. Triggers on .csproj, Program.cs, DbContext, MapGet/MapPost, IServiceCollection.

Tổng quan

Nhà phát hànhalpham8
Kho mãagentic-webdev
Tên kỹ năngaspnet-core
Sao
4
Bản fork
0
Tệp đi kèm
Chỉ có hướng dẫn
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được alpham8 công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Aspnet Core trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/alpham8/agentic-webdev/tree/master/skills/aspnet-core
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/alpham8/agentic-webdev.git /tmp/agentic-webdev
mkdir -p .claude/skills
cp -r /tmp/agentic-webdev/skills/aspnet-core .claude/skills/aspnet-core
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Aspnet Core trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Aspnet Core ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Aspnet Core với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

ASP.NET Core

Related Skills

NeedSkill
C# language referencecsharp
Svelte/SvelteKit frontendsvelte
TypeScript for frontendtypescript

Overview

ASP.NET Core is a cross-platform framework for building web APIs, real-time apps, and microservices on .NET. Current version: 9.0.

Architecture: Minimal APIs (no controllers), interface-based services, EF Core Code-First, JWT auth with Identity, SignalR for real-time.


Project Structure

src/
  MyApp.Api/
    Configuration/        # Options/settings classes
    Data/
      ActionBuddiesDbContext.cs
      Configurations/     # IEntityTypeConfiguration<T>
      Migrations/
      SeedData/
    Extensions/           # ServiceCollection + WebApplication extensions
      ServiceCollectionExtensions.cs
      WebApplicationExtensions.cs
      AuthEndpoints.cs
      PostEndpoints.cs
      ...
    Hubs/                 # SignalR hubs
    Middleware/            # Custom middleware
    Models/               # Entities, DTOs, requests/responses
    Services/             # Interface + implementation pairs
    Program.cs            # Entry point
    appsettings.json
  MyApp.Api.Tests.Unit/
  MyApp.Api.Tests.Integration/
  frontend/               # SvelteKit app

Program.cs (Minimal API Setup)

csharp
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

// Service registration
builder.Services.AddApplicationServices(builder.Configuration);
builder.Services.AddAuthenticationServices(builder.Configuration);
builder.Services.AddCachingServices(builder.Configuration);
builder.Services.AddSignalR();

WebApplication app = builder.Build();

// Middleware pipeline
app.UseSecurityHeaders();
app.UseAuthentication();
app.UseAuthorization();
app.UseRateLimiter();
app.UseOutputCache();

// Endpoint mapping
app.MapAuthEndpoints();
app.MapPostEndpoints();
app.MapChatEndpoints();
app.MapHub<NotificationHub>("/hubs/notifications");
app.MapHealthChecks("/health");

app.Run();

Minimal APIs

Endpoint Organization

csharp
// Extensions/PostEndpoints.cs
public static class PostEndpoints
{
    public static void MapPostEndpoints(this WebApplication app)
    {
        RouteGroupBuilder group = app.MapGroup("/api/v1/posts")
            .RequireAuthorization()
            .WithTags("Posts");

        group.MapGet("/", GetFeed);
        group.MapGet("/{id}", GetPost);
        group.MapPost("/", CreatePost);
        group.MapPut("/{id}", UpdatePost);
        group.MapDelete("/{id}", DeletePost);
        group.MapPost("/{id}/like", ToggleLike);
    }

    private static async Task<IResult> GetFeed(
        [FromQuery] int page,
        [FromQuery] string? network,
        IPostService postService,
        ClaimsPrincipal user,
        CancellationToken ct)
    {
        string userId = user.FindFirstValue(ClaimTypes.NameIdentifier)!;
        List<PostDto> posts = await postService.GetFeedAsync(userId, network, page, ct);
        return Results.Ok(posts);
    }

    private static async Task<IResult> CreatePost(
        CreatePostRequest request,
        IPostService postService,
        ClaimsPrincipal user)
    {
        string userId = user.FindFirstValue(ClaimTypes.NameIdentifier)!;
        PostDto post = await postService.CreateAsync(request, userId);
        return Results.Created($"/api/v1/posts/{post.Id}", post);
    }

    private static async Task<IResult> DeletePost(
        string id,
        IPostService postService,
        ClaimsPrincipal user)
    {
        string userId = user.FindFirstValue(ClaimTypes.NameIdentifier)!;
        bool deleted = await postService.DeleteAsync(id, userId);
        return deleted ? Results.NoContent() : Results.NotFound();
    }
}

Common Result Patterns

csharp
Results.Ok(data);                           // 200
Results.Created($"/api/v1/items/{id}", dto); // 201
Results.NoContent();                         // 204
Results.NotFound();                          // 404
Results.BadRequest("Validation failed");     // 400
Results.Unauthorized();                      // 401
Results.Forbid();                            // 403
Results.Problem("Internal error", statusCode: 500);

Dependency Injection

Service Registration

csharp
public static class ServiceCollectionExtensions
{
    public static IServiceCollection AddApplicationServices(
        this IServiceCollection services,
        IConfiguration configuration)
    {
        // Options pattern -- bind config sections
        services.Configure<JwtSettings>(configuration.GetSection("Jwt"));
        services.Configure<RedisSettings>(configuration.GetSection("Redis"));
        services.Configure<MinioSettings>(configuration.GetSection("Minio"));

        // Scoped services (per-request lifetime)
        services.AddScoped<IChatService, ChatService>();
        services.AddScoped<IPostService, PostService>();
        services.AddScoped<INotificationService, NotificationService>();

        // Singleton (shared across all requests)
        services.AddSingleton<ICacheService, RedisCacheService>();

        // Transient (new instance every injection)
        services.AddTransient<ITokenService, TokenService>();

        // DbContext
        services.AddDbContext<ActionBuddiesDbContext>(options =>
            options.UseNpgsql(configuration.GetConnectionString("DefaultConnection"))
                   .UseSnakeCaseNamingConvention());

        // DbContextFactory (for parallel queries)
        services.AddDbContextFactory<ActionBuddiesDbContext>(options =>
            options.UseNpgsql(configuration.GetConnectionString("DefaultConnection"))
                   .UseSnakeCaseNamingConvention());

        return services;
    }
}

Options Pattern

csharp
// Configuration class
public sealed class JwtSettings
{
    public required string Secret { get; init; }
    public required string Issuer { get; init; }
    public required string Audience { get; init; }
    public int ExpirationMinutes { get; init; } = 15;
}

// Bind in DI
services.Configure<JwtSettings>(configuration.GetSection("Jwt"));

// Inject via IOptions<T>
public sealed class TokenService(IOptions<JwtSettings> jwtOptions) : ITokenService
{
    private readonly JwtSettings _jwt = jwtOptions.Value;

    public string GenerateToken(ApplicationUser user)
    {
        // use _jwt.Secret, _jwt.Issuer, etc.
    }
}

Entity Framework Core

DbContext

csharp
public sealed class ActionBuddiesDbContext : IdentityDbContext<ApplicationUser>
{
    public DbSet<Post> Posts => Set<Post>();
    public DbSet<Comment> Comments => Set<Comment>();
    public DbSet<Chat> Chats => Set<Chat>();
    public DbSet<Sport> Sports => Set<Sport>();
    public DbSet<Spot> Spots => Set<Spot>();

    public ActionBuddiesDbContext(DbContextOptions<ActionBuddiesDbContext> options)
        : base(options) { }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.ApplyConfigurationsFromAssembly(typeof(ActionBuddiesDbContext).Assembly);
    }
}

Entity Configuration

csharp
public sealed class PostConfiguration : IEntityTypeConfiguration<Post>
{
    public void Configure(EntityTypeBuilder<Post> builder)
    {
        builder.HasKey(p => p.Id);
        builder.Property(p => p.Content).HasMaxLength(5000).IsRequired();
        builder.Property(p => p.CreatedAt).IsRequired();

        builder.HasOne(p => p.Author)
            .WithMany()
            .HasForeignKey(p => p.AuthorId)
            .OnDelete(DeleteBehavior.Cascade);

        builder.HasMany(p => p.Likes)
            .WithOne(l => l.Post)
            .HasForeignKey(l => l.PostId);

        // Compound index
        builder.HasIndex(p => new { p.NetworkSlug, p.CreatedAt })
            .IsDescending(false, true);
    }
}

Querying Patterns

csharp
// Eager loading with Include
List<Post> posts = await context.Posts
    .Include(p => p.Author)
    .Include(p => p.Likes)
    .Include(p => p.Comments)
        .ThenInclude(c => c.Author)
    .Where(p => p.NetworkSlug == networkSlug)
    .OrderByDescending(p => p.CreatedAt)
    .Take(20)
    .AsNoTracking()
    .ToListAsync(ct);

// Projection (better performance than Include)
List<PostDto> posts = await context.Posts
    .Where(p => p.AuthorId == userId)
    .OrderByDescending(p => p.CreatedAt)
    .Select(p => new PostDto
    {
        Id = p.Id,
        Content = p.Content,
        AuthorName = p.Author.DisplayName,
        LikeCount = p.Likes.Count,
        CommentCount = p.Comments.Count,
    })
    .ToListAsync(ct);

// Pagination
int totalCount = await context.Posts.CountAsync(p => p.NetworkSlug == slug, ct);
List<Post> page = await context.Posts
    .OrderByDescending(p => p.CreatedAt)
    .Skip((pageNumber - 1) * pageSize)
    .Take(pageSize)
    .ToListAsync(ct);

Migrations

bash
dotnet ef migrations add AddPostIndexes --project src/MyApp.Api
dotnet ef database update --project src/MyApp.Api
dotnet ef migrations remove --project src/MyApp.Api  # remove last unapplied

Authentication (JWT + Identity)

Setup

csharp
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
    options.Password.RequireDigit = true;
    options.Password.RequiredLength = 8;
    options.User.RequireUniqueEmail = true;
    options.SignIn.RequireConfirmedEmail = true;
})
.AddEntityFrameworkStores<ActionBuddiesDbContext>()
.AddDefaultTokenProviders();

services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
    options.TokenValidationParameters = new TokenValidationParameters
    {
        ValidateIssuer = true,
        ValidateAudience = true,
        ValidateLifetime = true,
        ValidateIssuerSigningKey = true,
        ValidIssuer = jwtSettings.Issuer,
        ValidAudience = jwtSettings.Audience,
        IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings.Secret)),
    };

    // Extract token from cookie or query string (for SignalR)
    options.Events = new JwtBearerEvents
    {
        OnMessageReceived = context =>
        {
            context.Token = context.Request.Cookies["ab_access"]
                ?? context.Request.Query["access_token"];
            return Task.CompletedTask;
        },
    };
});

Auth Endpoints

csharp
group.MapPost("/login", async (LoginRequest request, ITokenService tokenService,
    UserManager<ApplicationUser> userManager, HttpContext httpContext) =>
{
    ApplicationUser? user = await userManager.FindByEmailAsync(request.Email);
    if (user is null || !await userManager.CheckPasswordAsync(user, request.Password))
    {
        return Results.Unauthorized();
    }

    string token = tokenService.GenerateToken(user);

    // Set HTTPOnly cookie for SSO
    httpContext.Response.Cookies.Append("ab_access", token, new CookieOptions
    {
        HttpOnly = true,
        Secure = true,
        SameSite = SameSiteMode.Lax,
        Expires = DateTimeOffset.UtcNow.AddDays(7),
    });

    return Results.Ok(new { token });
});

SignalR

Hub

csharp
[Authorize]
public sealed class ChatHub : Hub
{
    public override async Task OnConnectedAsync()
    {
        string userId = Context.User!.FindFirstValue(ClaimTypes.NameIdentifier)!;
        await Groups.AddToGroupAsync(Context.ConnectionId, $"user-{userId}");
        await base.OnConnectedAsync();
    }

    public async Task SendMessage(string chatId, string content)
    {
        string senderId = Context.User!.FindFirstValue(ClaimTypes.NameIdentifier)!;
        // Save message via service, then broadcast
        ChatMessageDto message = await _chatService.SendMessageAsync(chatId, senderId, content);

        await Clients.Group($"chat-{chatId}").SendAsync("ReceiveMessage", message);
    }

    public override async Task OnDisconnectedAsync(Exception? exception)
    {
        string userId = Context.User!.FindFirstValue(ClaimTypes.NameIdentifier)!;
        await Groups.RemoveFromGroupAsync(Context.ConnectionId, $"user-{userId}");
        await base.OnDisconnectedAsync(exception);
    }
}

Sending from Services

csharp
public sealed class NotificationService(IHubContext<NotificationHub> hubContext) : INotificationService
{
    public async Task SendToUserAsync(string userId, NotificationDto notification)
    {
        await hubContext.Clients.Group($"user-{userId}")
            .SendAsync("ReceiveNotification", notification);
    }
}

Middleware

csharp
public sealed class SecurityHeadersMiddleware(RequestDelegate next)
{
    public async Task InvokeAsync(HttpContext context)
    {
        context.Response.Headers.Append("X-Content-Type-Options", "nosniff");
        context.Response.Headers.Append("X-Frame-Options", "DENY");
        context.Response.Headers.Append("Referrer-Policy", "strict-origin-when-cross-origin");
        context.Response.Headers.Append("Permissions-Policy", "camera=(), microphone=()");

        if (context.Request.IsHttps)
        {
            context.Response.Headers.Append("Strict-Transport-Security",
                "max-age=31536000; includeSubDomains");
        }

        await next(context);
    }
}

// Registration
app.UseMiddleware<SecurityHeadersMiddleware>();
// Or extension method:
app.UseSecurityHeaders();

Caching

Redis Cache Service

csharp
public interface ICacheService
{
    Task<T?> GetAsync<T>(string key, CancellationToken ct = default);
    Task SetAsync<T>(string key, T value, TimeSpan ttl, CancellationToken ct = default);
    Task RemoveAsync(string key, CancellationToken ct = default);
}

public sealed class RedisCacheService(IConnectionMultiplexer redis, ILogger<RedisCacheService> logger)
    : ICacheService
{
    private readonly IDatabase _db = redis.GetDatabase();

    public async Task<T?> GetAsync<T>(string key, CancellationToken ct)
    {
        try
        {
            RedisValue value = await _db.StringGetAsync(key);
            return value.IsNullOrEmpty ? default : JsonSerializer.Deserialize<T>(value!);
        }
        catch (RedisConnectionException ex)
        {
            logger.LogWarning(ex, "Redis unavailable, cache miss for {Key}", key);
            return default; // graceful degradation
        }
    }

    public async Task SetAsync<T>(string key, T value, TimeSpan ttl, CancellationToken ct)
    {
        try
        {
            string json = JsonSerializer.Serialize(value);
            await _db.StringSetAsync(key, json, ttl);
        }
        catch (RedisConnectionException ex)
        {
            logger.LogWarning(ex, "Redis unavailable, skipping cache set for {Key}", key);
        }
    }
}

Output Caching

csharp
builder.Services.AddOutputCache(options =>
{
    options.AddPolicy("Sports", builder => builder.Expire(TimeSpan.FromHours(24)));
    options.AddPolicy("Profiles", builder => builder.Expire(TimeSpan.FromMinutes(30)));
});

// Apply to endpoint
group.MapGet("/sports", GetSports).CacheOutput("Sports");

Rate Limiting

csharp
builder.Services.AddRateLimiter(options =>
{
    options.AddFixedWindowLimiter("auth", limiter =>
    {
        limiter.PermitLimit = 10;
        limiter.Window = TimeSpan.FromMinutes(1);
    });

    options.AddFixedWindowLimiter("global", limiter =>
    {
        limiter.PermitLimit = 100;
        limiter.Window = TimeSpan.FromMinutes(1);
    });

    options.RejectionStatusCode = StatusCodes.Status429TooManyRequests;
});

// Apply to endpoint group
group.MapPost("/login", Login).RequireRateLimiting("auth");

MassTransit (Message Bus)

csharp
// Message
public sealed record MediaProcessingMessage(string MediaId, string UserId, string FilePath);

// Consumer (handler)
public sealed class MediaProcessingConsumer(
    IMediaService mediaService,
    ILogger<MediaProcessingConsumer> logger) : IConsumer<MediaProcessingMessage>
{
    public async Task Consume(ConsumeContext<MediaProcessingMessage> context)
    {
        MediaProcessingMessage msg = context.Message;
        logger.LogInformation("Processing media {MediaId}", msg.MediaId);
        await mediaService.ProcessAsync(msg.MediaId, msg.FilePath);
    }
}

// Registration
services.AddMassTransit(config =>
{
    config.AddConsumer<MediaProcessingConsumer>();
    config.AddConsumer<ContentModerationConsumer>();

    config.UsingRabbitMq((ctx, cfg) =>
    {
        cfg.Host(rabbitMqSettings.Host, h =>
        {
            h.Username(rabbitMqSettings.Username);
            h.Password(rabbitMqSettings.Password);
        });
        cfg.ConfigureEndpoints(ctx);
    });
});

// Publishing
await publishEndpoint.Publish(new MediaProcessingMessage(mediaId, userId, filePath));

Health Checks

csharp
builder.Services.AddHealthChecks()
    .AddNpgSql(connectionString, name: "postgresql")
    .AddRedis(redisConnection, name: "redis")
    .AddCheck<Neo4jHealthCheck>("neo4j")
    .AddCheck<MinioHealthCheck>("minio");

app.MapHealthChecks("/health", new HealthCheckOptions
{
    ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
});

Testing

Unit Tests

csharp
public sealed class PostServiceTests
{
    private readonly ActionBuddiesDbContext _context;
    private readonly IPostService _sut;
    private readonly ICacheService _cache = Substitute.For<ICacheService>();

    public PostServiceTests()
    {
        DbContextOptions<ActionBuddiesDbContext> options = new DbContextOptionsBuilder<ActionBuddiesDbContext>()
            .UseInMemoryDatabase(Guid.NewGuid().ToString())
            .Options;

        _context = new ActionBuddiesDbContext(options);
        _sut = new PostService(_context, _cache, Substitute.For<ILogger<PostService>>());
    }

    [Fact]
    public async Task Should_CreatePost_When_ValidRequest()
    {
        // Arrange
        CreatePostRequest request = new() { Content = "Hello world", NetworkSlug = "skatebuddies" };

        // Act
        PostDto result = await _sut.CreateAsync(request, "user-123");

        // Assert
        result.Content.Should().Be("Hello world");
        result.AuthorId.Should().Be("user-123");
        (await _context.Posts.CountAsync()).Should().Be(1);
    }
}

Integration Tests

csharp
public sealed class AuthEndpointsTests : IClassFixture<WebApplicationFactory<Program>>
{
    private readonly HttpClient _client;

    public AuthEndpointsTests(WebApplicationFactory<Program> factory)
    {
        _client = factory.WithWebHostBuilder(builder =>
        {
            builder.ConfigureServices(services =>
            {
                // Replace real DB with in-memory
                services.RemoveAll<DbContextOptions<ActionBuddiesDbContext>>();
                services.AddDbContext<ActionBuddiesDbContext>(options =>
                    options.UseInMemoryDatabase("TestDb"));
            });
        }).CreateClient();
    }

    [Fact]
    public async Task Should_Return401_When_InvalidCredentials()
    {
        HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/login",
            new { Email = "wrong@test.com", Password = "wrong" });

        response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
    }
}

Docker

Dockerfile (Multi-Stage)

dockerfile
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
COPY ["src/MyApp.Api/MyApp.Api.csproj", "src/MyApp.Api/"]
RUN dotnet restore "src/MyApp.Api/MyApp.Api.csproj"
COPY . .
RUN dotnet publish "src/MyApp.Api/MyApp.Api.csproj" -c Release -o /app/publish

FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
WORKDIR /app
COPY --from=build /app/publish .
EXPOSE 8080
ENTRYPOINT ["dotnet", "MyApp.Api.dll"]

docker-compose.yml (Development)

yaml
services:
  api:
    build: .
    ports: ["8080:8080"]
    depends_on: [postgres, redis, rabbitmq]
  postgres:
    image: pgvector/pgvector:pg16
    environment:
      POSTGRES_DB: actionbuddies
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
  redis:
    image: redis:7-alpine
  rabbitmq:
    image: rabbitmq:3-management
  minio:
    image: minio/minio
    command: server /data --console-address ":9001"
  neo4j:
    image: neo4j:5

Common Gotchas

  1. DbContext is scoped -- Never inject DbContext into singleton services. Use IDbContextFactory<T> for parallel queries or background tasks.
  2. N+1 queries -- Always use .Include() or .Select() projections. Never access navigation properties in loops without eager loading.
  3. SignalR query string token -- WebSocket connections can't send headers. Use ?access_token= in query string for SignalR auth (MS-documented pattern).
  4. AsNoTracking() -- Always use for read-only queries. Tracked entities consume memory and slow down SaveChanges().
  5. Async in SignalR -- Hub methods must return Task. async void will crash the hub silently.
  6. MassTransit retry -- Configure retry strategy. Without it, failed consumers lose messages permanently.
  7. appsettings.json secrets -- Never commit real secrets. Use appsettings.Development.json (gitignored), environment variables, or User Secrets for dev.
  8. CORS + credentials -- When using cookies with CORS, set AllowCredentials() and list specific origins (no wildcards allowed).
  9. EF migration conflicts -- When multiple developers add migrations, snapshot conflicts arise. One developer removes their migration, applies the other, then re-creates.
  10. Output caching + auth -- Output cache does NOT respect authorization by default. Authenticated endpoints must use VaryByHeaderNames or skip caching.

Documentation References

Câu hỏi thường gặp

Kỹ năng AI Aspnet Core làm được gì?

Use when developing ASP.NET Core applications - Minimal APIs, dependency injection, middleware, Entity Framework Core, SignalR, authentication (JWT/Identity), configuration, health checks, caching, MassTransit, rate limiting. Triggers on .csproj, Program.cs, DbContext, MapGet/MapPost, IServiceCollection.

Vì sao nên dùng Aspnet Core trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Aspnet Core là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Aspnet Core trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/alpham8/agentic-webdev/tree/master/skills/aspnet-core. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Aspnet Core?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Aspnet Core với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Aspnet Core với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Aspnet Core có miễn phí không?

Kỹ năng này được alpham8 phát hành trên GitHub. Hãy xem điều khoản giấy phép trong kho mã. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇