This directory contains the modern IOptions<T> configuration classes for the SharePoint Sync Tool.
General application settings (name, version, environment, feature flags).
SharePoint Online connectivity settings with full validation:
- Username (required, email format)
- Password (required, use secrets management)
- SiteUrl (required, valid URL)
- Timeout and retry settings (range validated)
SQL Server connectivity and performance settings with validation:
- ConnectionString (required, use secrets management)
- CommandTimeout (range: 10-3600 seconds)
- BatchSize (range: 10-1000 items)
- EnforceEncryption flag
✅ Fail-Fast Validation - All configuration is validated at startup
✅ Strongly Typed - IntelliSense support and compile-time safety
✅ Testable - Easy to mock with Options.Create()
✅ Multiple Sources - JSON, environment variables, user secrets, command-line
✅ Secure - Supports secrets management out of the box
// Inject IOptions<T> in your service constructor
public class MyService
{
private readonly SharePointOptions _options;
public MyService(IOptions<SharePointOptions> options)
{
_options = options.Value; // Already validated!
}
public async Task DoWorkAsync()
{
// Use strongly-typed configuration
var client = new Client(_options.SiteUrl);
client.Timeout = TimeSpan.FromSeconds(_options.TimeoutSeconds);
}
}Configuration is loaded from multiple sources (priority order):
- Command-line arguments (highest)
- Environment variables (prefix:
SPO2SQL_) - User secrets (development only)
- appsettings.{Environment}.json
- appsettings.json (lowest)
NEVER commit sensitive data to source control!
Use user secrets for sensitive data:
dotnet user-secrets set "SharePoint:Password" "your-password"
dotnet user-secrets set "Sql:ConnectionString" "Server=..."Use environment variables:
export SPO2SQL_SharePoint__Password="your-password"
export SPO2SQL_Sql__ConnectionString="Server=..."Note: Double underscore __ represents configuration hierarchy.
See MIGRATION_GUIDE.md for complete details on migrating from the legacy XML ConfigHelper pattern to IOptions<T>.
All configuration classes use Data Annotations for validation:
[Required]- Value must be provided[EmailAddress]- Must be valid email format[Url]- Must be valid URL format[Range(min, max)]- Numeric values must be within range[MinLength(n)]- String must have minimum length
Validation happens at startup thanks to:
services.AddOptions<SharePointOptions>()
.ValidateDataAnnotations() // Enable attribute validation
.ValidateOnStart(); // Validate immediately (fail-fast)To add new configuration sections:
- Create a new options class (e.g.,
MyServiceOptions.cs) - Add validation attributes
- Register in
Program.cs:services.AddOptions<MyServiceOptions>() .Bind(context.Configuration.GetSection("MyService")) .ValidateDataAnnotations() .ValidateOnStart();
- Add section to
appsettings.json - Inject
IOptions<MyServiceOptions>where needed
Mock configuration in unit tests:
var mockOptions = Options.Create(new SharePointOptions
{
SiteUrl = "https://test.sharepoint.com",
Username = "test@test.com",
Password = "test-password",
TimeoutSeconds = 30
});
var service = new MyService(mockOptions);- Application.cs - Demonstrates IOptions<T> patterns
- Program.cs - Configuration registration
- appsettings.json - Configuration values
- MIGRATION_GUIDE.md - XML to IOptions migration guide