ASP.NET MVC Snippets

Professional, production-ready ASP.NET MVC code snippets for C# — scaffolding controllers, repositories, services, models, LINQ queries, and more in seconds.
✨ Features
- 12 carefully crafted snippets covering the full MVC/Clean Architecture stack
- Works exclusively in
.cs (C#) files — no accidental triggering
- Follows ASP.NET Core best practices: null guards, async/await,
AsNoTracking, and structured logging
- Every snippet uses tab stops so you can fill in your entity name once and propagate it throughout
- Covers the complete vertical slice: Controller → Service → Repository → DbContext → Model/DTO
📦 Installation
From VS Code Marketplace
- Open VS Code
- Press
Ctrl+P (or Cmd+P on macOS)
- Type
ext install your-publisher-name.aspnet-mvc-snippets
- Press Enter
From the Extensions panel
- Click the Extensions icon in the Activity Bar (
Ctrl+Shift+X)
- Search for ASP.NET MVC Snippets
- Click Install
Manual (VSIX)
- Download the latest
.vsix from GitHub Releases
- In VS Code:
Extensions → ... menu → Install from VSIX…
- Select the downloaded file
🚀 Usage
- Open any
.cs file in your ASP.NET project
- Type a snippet prefix (e.g.
mvc-controller)
- Select the suggestion from IntelliSense or press Tab
- Fill in the first tab stop (usually your entity name) — it auto-propagates
- Press Tab to advance through remaining placeholders
Tip: All tab stops are ordered so that typing your entity name once fills it in everywhere it appears.
📋 Snippet Reference
| Prefix |
What it generates |
mvc-controller |
Full API controller with GET/POST/PUT/DELETE, DI, and logging |
mvc-interface |
Typed repository interface with async CRUD signatures |
mvc-repository |
EF Core repository implementation (CRUD + AsNoTracking) |
mvc-di |
DI constructor with null guards and ILogger |
mvc-action |
Single async IActionResult method with HTTP verb picker |
mvc-crud |
CRUD service methods with DTO mapping helpers |
mvc-model |
Entity class with Data Annotations and audit fields |
mvc-service |
Service interface + implementation with logging |
mvc-linq |
Common EF Core LINQ patterns (filter, project, paginate, include) |
mvc-validation |
DTO class with full Data Annotations validation |
mvc-dbcontext |
DbContext with DbSet and Fluent API configuration |
mvc-program |
Complete Program.cs service registration block |
mvc-middleware |
Global exception handling middleware with JSON response |
🖥️ Example — Scaffold a Feature in Under 2 Minutes
1. Model (mvc-model)
[Table("Products")]
public class Product
{
[Key]
public int Id { get; set; }
[Required]
[StringLength(200)]
public string Name { get; set; } = string.Empty;
public bool IsActive { get; set; } = true;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime? UpdatedAt { get; set; }
}
2. Repository Interface (mvc-interface)
public interface IProductRepository
{
Task<IEnumerable<Product>> GetAllAsync();
Task<Product?> GetByIdAsync(int id);
Task<Product> AddAsync(Product entity);
Task<Product?> UpdateAsync(Product entity);
Task<bool> DeleteAsync(int id);
Task<bool> ExistsAsync(int id);
}
3. Repository (mvc-repository)
public class ProductRepository : IProductRepository
{
private readonly AppDbContext _context;
// ... full EF Core implementation
}
4. Service (mvc-service)
public class ProductService : IProductService
{
private readonly IProductRepository _repository;
private readonly ILogger<ProductService> _logger;
// ... full service implementation
}
5. Controller (mvc-controller)
[ApiController]
[Route("api/[controller]")]
public class ProductController : ControllerBase
{
// GET /api/product
// GET /api/product/{id}
// POST /api/product
// PUT /api/product/{id}
// DELETE /api/product/{id}
}
🔧 Requirements
| Requirement |
Version |
| Visual Studio Code |
^1.90.0 |
| Target language |
C# (.cs files only) |
| .NET SDK |
6.0 / 7.0 / 8.0 |
This extension provides snippets only — no runtime components, no language server, no build tasks.
🤝 Contributing
Pull requests are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feat/my-snippet)
- Add your snippet to
snippets/mvc.code-snippets
- Update this README's snippet table
- Open a Pull Request
📤 Publishing to the VS Code Marketplace
Prerequisites
npm install -g @vscode/vsce
One-time setup
- Create a publisher account at marketplace.visualstudio.com
- Generate a Personal Access Token (PAT) with Marketplace → Manage scope
- Add your publisher name to
package.json → "publisher" field
Login
vsce login your-publisher-name
# Paste your PAT when prompted
Package (VSIX only — no publish)
vsce package
# Outputs: aspnet-mvc-snippets-1.0.0.vsix
Publish
vsce publish
# Bumps patch and publishes
Bump version and publish
vsce publish minor # 1.0.0 → 1.1.0
vsce publish major # 1.0.0 → 2.0.0
vsce publish patch # 1.0.0 → 1.0.1
📄 License
MIT © Your Name