create-dto-viewmodel

Scaffolds C# DTOs and ViewModels with static extension method mappings from domain entities.

Updated Nov 19, 2020
One-click install
npx skills add https://github.com/kwojtasinski-repo/ECommerceApp --skill create-dto-viewmodel-kwojtasinski-repo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: create-dto-viewmodel
Source: https://github.com/kwojtasinski-repo/ECommerceApp/tree/main/.github/skills/create-dto-viewmodel
Command: npx skills add https://github.com/kwojtasinski-repo/ECommerceApp --skill create-dto-viewmodel-kwojtasinski-repo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Manually writing DTOs, ViewModels, and their mapping code is repetitive and error-prone, especially when migrating away from AutoMapper. This Skill generates consistent DTO/ViewModel classes plus static extension method mappings (ToDto/ToViewModel) that follow the project's AutoMapper removal strategy. ## Core Features & Use Cases - DTO and ViewModel Scaffolding: Creates record-based DTOs for the API layer or mutable ViewModel classes for MVC views, placed in the correct Application layer folder. - Extension Method Mappings: Generates an internal static Mappings class with ToDto()/ToDtoList() extension methods, including nested child mapping and reverse Dto-to-Command mapping templates. - AutoMapper Migration Checklist: Provides a step-by-step checklist to swap _mapper.Map calls to extension methods and remove legacy IMapFrom/CreateMap registrations. - Use Case: When adding a new bounded context like Sales/Orders, generate an OrderDto with an OrderMappings extension class instead of configuring AutoMapper profiles. ## Quick Start Ask the AI to create a DTO for the Order entity in the Sales/Orders bounded context using extension method mapping.

Frequently Asked Questions about create-dto-viewmodel

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a DTO without AutoMapper in C#?

Create a record or class exposing only the properties the consumer needs, then add an internal static Mappings class with a ToDto() extension method that constructs the DTO from the domain entity. This replaces IMapFrom and CreateMap registrations.

When should I use a DTO versus a ViewModel in ASP.NET Core?

Use a DTO (record with a Dto suffix) for the API layer, placed under Application/{Module}/{BC}/Dto. Use a ViewModel (mutable class with a Vm suffix) for MVC views in the Web layer, especially when views need settable properties or nested collections.

Can I mix AutoMapper and extension method mapping in the same bounded context?

No. The mapping strategy requires consistency within a bounded context: pick either AutoMapper or extension methods and stay with it. AutoMapper remains only for legacy artifacts already using IMapFrom; new bounded contexts should use extension methods.

How do I migrate an existing bounded context away from AutoMapper?

Create the DTO with extension mapping, replace _mapper.Map calls with ToDto(), remove IMapFrom implementations and CreateMap profile entries, then run dotnet build and dotnet test to confirm no missing registrations, and add unit tests for the extension methods.

Should DTOs expose all properties of the domain entity?

No. DTOs should expose only what the consumer layer needs, keep nullable properties nullable, and unwrap typed IDs to plain int values so DTOs do not depend on domain value objects.