skills/dotnet/patterns/result-wrapper/SKILL.md
Use Result wrapper pattern for explicit error handling without exceptions in .NET applications. Use when: - Handling business errors explicitly without exceptions - Building functional error handling pipelines - Separating business errors from system errors - Creating composable error handling flows - Implementing railway-oriented programming patterns Triggers: "result wrapper", "result pattern", "error handling", "railway oriented", "functional error", "maybe pattern"
npx skillsauth add yeeehaooo/WorkSpace result-wrapperInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use Result<T> wrapper pattern for explicit error handling without exceptions.
Applies to:
Result<T> for business errors (validation, business rules)Result<T> is immutableMap, Bind, Match methodsResult<T> type defined in Application layerResult<T> for business failuresResult<T> valuesResult<T> failuresResult<T> from infrastructure (should convert exceptions)// Application Layer
public class Result<T>
{
public bool IsSuccess { get; }
public T? Value { get; }
public string? Error { get; }
public ErrorCode? ErrorCode { get; }
private Result(bool isSuccess, T? value, string? error, ErrorCode? errorCode = null)
{
IsSuccess = isSuccess;
Value = value;
Error = error;
ErrorCode = errorCode;
}
public static Result<T> Success(T value) => new(true, value, null);
public static Result<T> Failure(string error, ErrorCode? errorCode = null) => new(false, default, error, errorCode);
public Result<TOut> Map<TOut>(Func<T, TOut> mapper)
{
return IsSuccess ? Result<TOut>.Success(mapper(Value!)) : Result<TOut>.Failure(Error!, ErrorCode);
}
public Result<TOut> Bind<TOut>(Func<T, Result<TOut>> binder)
{
return IsSuccess ? binder(Value!) : Result<TOut>.Failure(Error!, ErrorCode);
}
public TOut Match<TOut>(Func<T, TOut> onSuccess, Func<string, TOut> onFailure)
{
return IsSuccess ? onSuccess(Value!) : onFailure(Error!);
}
}
// Domain Usage
public class Order : AggregateRoot
{
public Result<Order> Create(CreateOrderRequest request)
{
if (request.Items.Count == 0)
return Result<Order>.Failure("Order must have at least one item", ErrorCode.OrderEmpty);
if (request.TotalAmount <= 0)
return Result<Order>.Failure("Order total must be greater than zero", ErrorCode.InvalidAmount);
var order = new Order
{
Id = Guid.NewGuid(),
Items = request.Items,
TotalAmount = request.TotalAmount
};
return Result<Order>.Success(order);
}
}
// Handler Usage
public class CreateOrderHandler : ICommandHandler<CreateOrderCommand>
{
public async Task<Result<OrderId>> Handle(CreateOrderCommand cmd, CancellationToken ct)
{
return await _orderRepo
.CreateAsync(cmd.Request, ct)
.Bind(order => SaveOrderAsync(order, ct))
.Map(order => order.Id);
}
}
development
Create reusable .NET atomic capability code snippets that can be directly copied and pasted. Use when: - Creating single-purpose code snippets - Building reusable code templates - Implementing atomic technical capabilities - Creating copy-pasteable code blocks - Building snippet library for common patterns Triggers: "create snippet", "code snippet", "reusable snippet", "atomic snippet", "copy-paste code"
development
Create Docker Compose configuration for containerized .NET application development and deployment. Use when: - Containerizing .NET applications - Setting up local development environment with dependencies - Creating multi-container setups (API + DB + Redis) - Defining service dependencies and networking - Building docker-compose.yml for development or production Triggers: "docker compose", "containerize", "multi-container", "docker-compose.yml", "docker setup"
tools
Create adapter structure for integrating third-party APIs in Clean Architecture applications. Use when: - Integrating external APIs or services - Creating HTTP client adapters for third-party services - Implementing API integration with error handling - Setting up adapter pattern for external dependencies - Building resilient external service integrations Triggers: "api adapter", "third-party api", "external service", "http client adapter", "api integration"
development
Enterprise backend structure built on Clean Architecture, DDD, CQRS, and Vertical Slice API Design with Dapper-first persistence. Use when: - Creating new enterprise backend projects - Implementing Clean Architecture with DDD and CQRS - Building vertical slice API endpoints - Using Dapper as primary persistence mechanism - Organizing modules by UseCase-driven and Model-driven separation Triggers: "dmis structure", "clean architecture", "enterprise backend", "DDD CQRS", "vertical slice", "dapper"