Skip to content

Commit ae25800

Browse files
authored
Add documentation for configuration sources and rules
Document configuration sources, precedence rules, and best practices for UltimateAuth.
1 parent 9450012 commit ae25800

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# ⚙️ Configuration Sources
2+
3+
UltimateAuth supports multiple configuration sources.
4+
5+
👉 But more importantly, it defines a **clear and predictable precedence model**
6+
7+
## 🧠 Two Ways to Configure
8+
9+
UltimateAuth can be configured using:
10+
11+
### 🔹 Code (Program.cs)
12+
13+
```csharp
14+
builder.Services.AddUltimateAuthServer(o =>
15+
{
16+
o.Login.MaxFailedAttempts = 5;
17+
});
18+
```
19+
20+
### 🔹 Configuration Files (appsettings.json)
21+
22+
```json
23+
{
24+
"UltimateAuth": {
25+
"Server": {
26+
"Login": {
27+
"MaxFailedAttempts": 5
28+
}
29+
}
30+
}
31+
}
32+
```
33+
34+
## ⚖️ Precedence Rules
35+
36+
This is the most important rule:
37+
38+
👉 **Configuration files override code**
39+
40+
Execution order:
41+
42+
```
43+
Program.cs configuration
44+
45+
appsettings.json binding
46+
47+
Final options
48+
```
49+
50+
👉 This means:
51+
52+
- Defaults can be defined in code
53+
- Environments can override them safely
54+
55+
<br>
56+
57+
## 🌍 Environment-Based Configuration
58+
59+
ASP.NET Core supports environment-specific configuration:
60+
61+
- appsettings.Development.json
62+
- appsettings.Staging.json
63+
- appsettings.Production.json
64+
65+
Example:
66+
67+
```json
68+
{
69+
"UltimateAuth": {
70+
"Server": {
71+
"Session": {
72+
"IdleTimeout": "7.00:00:00"
73+
}
74+
}
75+
}
76+
}
77+
```
78+
79+
👉 You can use different values per environment without changing code
80+
81+
<br>
82+
83+
## 🧩 Recommended Strategy
84+
85+
For real-world applications:
86+
87+
### ✔ Use Program.cs for:
88+
- Defaults
89+
- Development setup
90+
- Local testing
91+
92+
### ✔ Use appsettings for:
93+
- Environment-specific overrides
94+
- Production tuning
95+
- Deployment configuration
96+
97+
👉 This keeps your system flexible and maintainable
98+
99+
<br>
100+
101+
## 🛡 Safety & Validation
102+
103+
UltimateAuth validates configuration at startup:
104+
105+
- Invalid combinations are rejected
106+
- Missing required values fail fast
107+
- Unsafe configurations are blocked
108+
109+
110+
👉 You will not run with a broken configuration
111+
112+
113+
## ⚠️ Common Pitfalls
114+
115+
### ❌ Assuming code overrides config
116+
117+
It does not.
118+
119+
👉 appsettings.json always wins
120+
121+
### ❌ Hardcoding production values
122+
123+
Avoid:
124+
125+
```csharp
126+
o.Token.AccessTokenLifetime = TimeSpan.FromHours(1);
127+
```
128+
129+
👉 Use environment config instead for maximum flexibility
130+
131+
132+
### ❌ Mixing environments unintentionally
133+
134+
Ensure correct environment is set:
135+
136+
```
137+
ASPNETCORE_ENVIRONMENT=Production
138+
```
139+
140+
<br>
141+
142+
## 🧠 Mental Model
143+
144+
If you remember one thing:
145+
146+
👉 Code defines defaults
147+
👉 Configuration defines reality
148+
149+
## 📌 Key Takeaways
150+
151+
- UltimateAuth supports code + configuration
152+
- appsettings.json overrides Program.cs
153+
- Environment-based configuration is first-class
154+
- Validation prevents unsafe setups
155+
- Designed for real-world deployment
156+
157+
## ➡️ Next Step
158+
159+
Continue to **Advanced Configuration**

0 commit comments

Comments
 (0)