โ๏ธ ๐๐ก๐๐ญ ๐ข๐ฌ ๐ญ๐ก๐ ๐๐ฉ๐ญ๐ข๐จ๐ง๐ฌ ๐ฉ๐๐ญ๐ญ๐๐ซ๐ง?
You can represent related settings using classes, which gives you strong typing for those settings.
โจ Benefits:
By applying this pattern, your app follows two important software engineering principles:
๐ ๐๐ง๐๐๐ฉ๐ฌ๐ฎ๐ฅ๐๐ญ๐ข๐จ๐ง โ services only depend on the settings they actually use.
๐งฉ ๐๐๐ฉ๐๐ซ๐๐ญ๐ข๐จ๐ง ๐จ๐ ๐๐จ๐ง๐๐๐ซ๐ง๐ฌ โ configuration logic is separated from business logic.
โก ๐ถ๐๐๐๐๐๐ ๐ฐ๐๐๐๐๐๐๐๐๐ ๐๐ .๐ต๐ฌ๐ป
๐๐๐ฉ๐ญ๐ข๐จ๐ง๐ฌ
โข Reads configuration once at startup.
โข โ Doesnโt update if config changes while the app is running.
โข ๐ข Registered as Singleton, can be injected anywhere.
๐๐๐ฉ๐ญ๐ข๐จ๐ง๐ฌ๐๐ง๐๐ฉ๐ฌ๐ก๐จ๐ญ
โข Reads configuration fresh on every request.
โข Useful for per-request updates (e.g., in web apps).
โข ๐ก Registered as Scoped, so cannot be injected into Singletons.
๐๐๐ฉ๐ญ๐ข๐จ๐ง๐ฌ๐๐จ๐ง๐ข๐ญ๐จ๐ซ
โข Supports real-time updates without restarting the app.
โข Can trigger callbacks when config changes.
โข ๐ข Registered as Singleton, safe to inject anywhere.
๐ก** Quick Summary**
โข IOptions โ Static, simple, app startup only.
โข IOptionsSnapshot โ Per-request updates.
โข IOptionsMonitor โ Real-time updates with change notifications.
โ Which one have you used the most in your projects?
Top comments (0)