Repository navigation
Add module options pattern with IModuleOptions interface - #23
Merged
Merged
Conversation
Modules can now expose configurable options via the IModuleOptions marker
interface. The source generator auto-discovers these classes and generates
typed Configure{Module}() extension methods on SimpleModuleOptions, enabling
host apps to customize module behavior without modifying module code.
- Add IModuleOptions marker interface to SimpleModule.Core
- Generator discovers IModuleOptions in module and contracts assemblies
- Generate ConfigureProducts() (etc.) extension methods per module
- Register IOptions<T> defaults and apply user overrides at startup
- Add SM0044 (multiple options per module) and SM0045 (orphan options) diagnostics
- Add ProductsModuleOptions as reference implementation
- Wire IOptions<ProductsModuleOptions> into Products BrowseEndpoint
Auto-generated types.ts files updated by source generator during build.
Add IModuleOptions implementations for 8 modules with meaningful, production-relevant configurable values: - AuditLogs: batch size, flush interval, retention days, check interval - Admin: users page size - FileStorage: max file size (MB), allowed extensions - Orders: default/max page size - PageBuilder: max title/slug lengths - Users: password policy (min length, digit/case requirements), lockout - Settings: cache duration for settings and public menu - Products: default/max page size (from prior commit) Wire options into module code replacing hardcoded constants: - AuditWriterService reads batch size and flush interval from options - AuditRetentionService reads retention days and check interval - Admin UsersEndpoint reads page size from options - Users module bridges UsersModuleOptions into Identity options - SettingsService and PublicMenuService read cache duration from options Add comprehensive tests: - 7 generator tests: discovery, extension method generation, defaults registration, multi-module, empty case, SM0044 diagnostic, hosting wiring - 9 integration tests: verify all module options resolve with correct defaults via IOptions<T> from the real DI container - 1 override test: verify all 8 module options can be overridden via services.Configure<T>() (simulating host app customization)
Address code review findings: - Extract FindConcreteClassesImplementing() shared namespace walker to eliminate duplication between FindModuleOptionsClasses and similar recursive discovery methods - Extract ModuleOptionsRecord.GroupByModule() to deduplicate identical dictionary-building logic in DiagnosticEmitter and ModuleOptionsEmitter - Remove ModuleOptionsInfo mutable class — build ModuleOptionsRecord directly during discovery (no mutable accumulation needed) - Remove unreachable SM0045 diagnostic — discovery only scans known module assemblies, so orphan options classes cannot occur - Use ScanModuleAssemblies helper for module options discovery to get assembly-level deduplication (consistent with interceptor discovery) - Align IModuleOptions pragma comment style with IModulePermissions
antosubash
force-pushed
the
claude/improve-module-extendability-SFKKL
branch
from
March 28, 2026 19:25
9c82566 to
14acb60
Compare
…-extendability-SFKKL
Deploying simplemodule-website with
|
| Latest commit: |
e17fd59
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f9266e44.simplemodule-website.pages.dev |
| Branch Preview URL: | https://claude-improve-module-extend.simplemodule-website.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements a configurable module options pattern that allows host applications to override module behavior at startup. Modules define options classes implementing
IModuleOptions, which are auto-discovered by the source generator and exposed as typedConfigure{Module}()extension methods onSimpleModuleOptions.Key Changes
IModuleOptionsmarker interface (SimpleModule.Core) — Base interface for module options classesSymbolDiscoveryto scan module and contracts assemblies forIModuleOptionsimplementationsModuleOptionsEmitter— New code generator that:Configure{Module}()extension methods onSimpleModuleOptionsRegisterModuleOptionsDefaults()to registerIOptions<T>for all discovered optionsSimpleModuleOptionsenhancements — AddedConfigureModule()andApplyModuleOptions()methods to support the configuration pipelineIModuleOptionsimplementations (at most one per module)ProductsModuleOptions(DefaultPageSize, MaxPageSize)OrdersModuleOptions(DefaultPageSize, MaxPageSize)UsersModuleOptions(password and lockout policies)AuditLogsModuleOptions(batch size, flush interval, retention)AdminModuleOptions(UsersPageSize)FileStorageModuleOptions(MaxFileSizeMb, AllowedExtensions)PageBuilderModuleOptions(MaxTitleLength, MaxSlugLength)SettingsModuleOptions(CacheDuration)ApplyUsersModuleOptions— Post-configuration hook that bridgesUsersModuleOptionsinto ASP.NET Identity'sIdentityOptionsIOptions<T>instead of hardcoded valuesModuleOptionsEmitterTests(generator behavior) andModuleOptionsTests(runtime resolution and overrides)Implementation Details
builder.AddSimpleModule(o => o.ConfigureProducts(p => p.MaxPageSize = 50))IOptions<T>dependency injection