git-agent for C#

Conventional commits for .NET and C# projects

git-agent understands .NET solution structure, ASP.NET Core middleware patterns, Entity Framework migrations, and C# language features, producing accurate conventional commits for enterprise .NET codebases.

diff --git a/src/Services/OrderService.cs b/src/Services/OrderService.cs index 4d1e2f3..9a8b7c6 100644 --- a/src/Services/OrderService.cs +++ b/src/Services/OrderService.cs @@ -5,15 +5,24 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; -public class OrderService +public class OrderService(ILogger<OrderService> logger, AppDbContext db) { - private readonly AppDbContext _db; - public OrderService(AppDbContext db) { _db = db; } - - public async Task<Order> CreateOrder(CreateOrderRequest request) + public async Task<Order> CreateOrder(CreateOrderRequest request) { + ArgumentNullException.ThrowIfNull(request); + using var transaction = await db.Database.BeginTransactionAsync(); try { - var order = new Order(request); - _db.Orders.Add(order); - await db.SaveChangesAsync(); + var order = new Order(request); + db.Orders.Add(order); + await db.SaveChangesAsync(); + await transaction.CommitAsync(); + logger.LogInformation("Created order {OrderId}", order.Id); return order; } - catch (DbUpdateException ex) + catch (DbUpdateException ex) when (ex.InnerException?.Message.Contains("IX_Orders_Number") == true) { + await transaction.RollbackAsync(); throw new OrderConflictException(request.Number, ex); } } }
git-agent output
refactor(orders): migrate to primary constructors and add transactional safety - convert OrderService to use C# 12 primary constructor syntax - add ArgumentNullException guard for request parameter - wrap persist in explicit transaction with rollback on conflict - catch filtered DbUpdateException for duplicate order number specifically - add structured logging for order creation events The traditional constructor pattern added unnecessary boilerplate; primary constructors make the dependency contract explicit at the class declaration site. The transaction ensures partial writes are rolled back if either SaveChanges or logging fails.
  • Understands .NET solution and project reference structure for scope detection
  • Recognises Entity Framework migration files and separates them into db commits
  • Handles ASP.NET Core middleware pipeline and endpoint configuration changes
  • Works with both .csproj and modern SDK-style project files
brew install gitagenthq/brew/git-agent # inside your .NET project git-agent init # detects .sln / .csproj structure and suggests scopes
Does git-agent handle .NET SDK and runtime version changes?
Yes. global.json and TargetFramework changes in .csproj files are detected as build configuration changes and committed separately as chore commits.
How does git-agent handle Entity Framework migrations?
Migration files in Migrations/ directories are grouped into a separate db commit. The Snapshot and Designer files that accompany a migration stay with the migration file.
Can git-agent work with Blazor projects?
Yes. Blazor component files (.razor), code-behind files, and Razor class library changes are all handled. The LLM understands the Blazor component lifecycle and rendering model.