一键导入
technology-stack
Core dependencies and versions, custom mediator implementation. Use when adding dependencies or checking version compatibility.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Core dependencies and versions, custom mediator implementation. Use when adding dependencies or checking version compatibility.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Minimal API endpoint patterns with IEndpointDefinition, filters, error handling. Use when creating or modifying API endpoints.
Perform a thorough architecture review of a .NET project examining structure, maintainability, clarity, robustness, and goal achievement. Use when the user asks to review, audit, or examine a codebase.
CQRS implementation — commands use EF Core DbContext, queries use Dapper IDbConnection. Use when implementing or modifying command/query handlers.
Perform a thorough architecture review of a .NET project examining structure, maintainability, clarity, robustness, and goal achievement. Use when the user asks to review, audit, or examine a codebase.
EF Core configuration, value object embedding, DbUp migrations, Aspire setup. Use when modifying database schema, migrations, or data access code.
Domain entity and value object patterns — private setters, factory methods, Reconstitute. Use when creating or modifying domain models.
| name | technology-stack |
| description | Core dependencies and versions, custom mediator implementation. Use when adding dependencies or checking version compatibility. |
| user-invocable | false |
/scalar/v1)Gen.OneOf)Custom CQRS Mediator (replaces commercial MediatR). The public contract:
public interface IMediator
{
// Single dispatch path: every request is IRequest<TResponse>, so every command/query runs
// through the same IPipelineBehavior chain. Commands with no natural result return Unit.
Task<TResponse> SendAsync<TResponse>(IRequest<TResponse> request, CancellationToken cancellationToken = default);
}
public interface IRequest<out TResponse> { }
public interface IRequestHandler<in TRequest, TResponse> where TRequest : IRequest<TResponse>
{
Task<TResponse> HandleAsync(TRequest request, CancellationToken cancellationToken);
}
The implementation (StarterApp.Api/Infrastructure/Mediator/Mediator.cs) deliberately avoids
MethodInfo.Invoke. It runs a feature-toggle gate and validators, then dispatches through a
strongly-typed wrapper that is built once per request type and cached for the process lifetime
(ConcurrentDictionary<Type, object>). Every subsequent SendAsync is a dictionary lookup plus a
strongly-typed virtual call — no per-call MethodInfo.Invoke, no object[] argument allocation:
public Task<TResponse> SendAsync<TResponse>(IRequest<TResponse> request, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(request);
RunFeatureToggleGate(request); // [FeatureToggle("name")] → FeatureDisabledException (503) before anything else
RunValidators(request); // every command/query has a validator (convention-enforced)
var wrapper = (RequestHandlerWrapper<TResponse>)RequestHandlerWrappers.GetOrAdd(
request.GetType(),
static (requestType, responseType) =>
Activator.CreateInstance(typeof(RequestHandlerWrapperImpl<,>).MakeGenericType(requestType, responseType))!,
typeof(TResponse));
return wrapper.HandleAsync(request, _serviceProvider, cancellationToken);
}
// Inside RequestHandlerWrapperImpl<TRequest, TResponse>: resolves IRequestHandler<TRequest, TResponse>,
// wraps the call in the IPipelineBehavior<TRequest, TResponse> chain (registration order, first
// registered runs outermost), and invokes handler.HandleAsync(typed, cancellationToken) directly.
Benefits: No commercial licensing, simple transparent implementation, full control over dispatch. The per-request-type wrapper is created once and cached, so dispatch carries no per-call reflection cost; the feature-toggle gate, validators, and pipeline behaviors are all centralized in this one path.