Standard collaboration patterns for all squad agents — worktree awareness, decisions, cross-agent communication
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.
Migrate from manual configuration binding to ASP.NET Core IOptions pattern
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.
설치 방법 보기설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.
Category: .NET Configuration
Complexity: Intermediate
Tags: #aspnetcore #ioptions #configuration #dependency-injection
config.Bind() + TryAddSingleton() pattern to ASP.NET Core IOptionsBefore:
var settings = new MySettings();
builder.Configuration.Bind("MySection", settings);
builder.Services.TryAddSingleton<IMySettings>(settings);
After:
builder.Services.Configure<MySettings>(builder.Configuration.GetSection("MySection"));
builder.Services.AddOptions<MySettings>()
.ValidateDataAnnotations()
.ValidateOnStart();
Before:
public class MyService
{
private readonly IMySettings _settings;
public MyService(IMySettings settings)
{
_settings = settings;
}
}
After:
using Microsoft.Extensions.Options;
public class MyService
{
private readonly MySettings _settings;
public MyService(IOptions<MySettings> settingsOptions)
{
_settings = settingsOptions.Value;
}
}
Before:
var mockSettings = new Mock<IMySettings>();
mockSettings.Setup(s => s.Property).Returns("value");
var sut = new MyService(mockSettings.Object);
After:
using Microsoft.Extensions.Options;
var settings = new MySettings { Property = "value" };
var settingsOptions = Options.Create(settings);
var sut = new MyService(settingsOptions);
using System.ComponentModel.DataAnnotations;
public class MySettings
{
[Required]
[Url]
public required string ApiBaseUrl { get; set; }
[Range(1, 3600)]
public int TimeoutSeconds { get; set; } = 30;
}
Razor views should inject IOptions<T> and unwrap in a code block:
@using Microsoft.Extensions.Options
@inject IOptions<Settings> SettingsOptions
@{
var settings = SettingsOptions.Value;
}
<img src="@settings.StaticContentRootUrl/logo.png" />
If unwrapping in constructor, store the unwrapped value:
private readonly string _apiUrl;
public MyService(IOptions<Settings> options)
{
_apiUrl = options.Value.ApiUrl; // ✅ Unwrap once, store value
}
Pick one pattern per project for consistency.
Use IOptionsSnapshot<T> instead of IOptions<T> if:
builder.Services.AddScoped<IMyService, MyService>();
public MyService(IOptionsSnapshot<MySettings> settings) { }
builder.Services.AddOptions<MySettings>()
.ValidateDataAnnotations()
.ValidateOnStart();
builder.Services.AddOptions<MySettings>()
.Validate(settings => !string.IsNullOrWhiteSpace(settings.ApiKey),
"ApiKey must be provided")
.ValidateOnStart();
public class MySettingsValidator : IValidateOptions<MySettings>
{
public ValidateOptionsResult Validate(string? name, MySettings options)
{
if (string.IsNullOrWhiteSpace(options.ApiKey))
return ValidateOptionsResult.Fail("ApiKey is required");
return ValidateOptionsResult.Success;
}
}
builder.Services.AddSingleton<IValidateOptions<MySettings>, MySettingsValidator>();
✅ Early validation (fail-fast at startup)
✅ Better testability (Options.Create() for tests)
✅ Standard ASP.NET Core pattern
✅ Supports config reloading (with IOptionsSnapshot)
✅ Type-safe configuration access
아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.
로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.
아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.
Standard collaboration patterns for all squad agents — worktree awareness, decisions, cross-agent communication
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.
Shared hard rules enforced across all squad agents
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.
Comprehensive AI prompt engineering safety review and improvement prompt. Analyzes prompts for safety, bias, security vulnerabilities, and effectiveness while providing detailed improvement recommendations with extensive frameworks, testing methodologies, and educational content.
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.
Migrate API controller scope checks to framework-enforced authorization policies while preserving ownership checks.
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.
Review API DTO implementations for contract/domain separation, mapping patterns, and REST compliance
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.
Register shared claims transformation and hierarchical role policies in the API without breaking existing scope enforcement.
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.