Collect user messages through ModelStateWrapper¶
Record error, warning, and informational messages while de-duplicating repeated text. Trigger: Domain or service code writing messages through IMessageContainer.
| Field | Value |
|---|---|
| Operation ID | OP-17 |
| Trigger | Domain or service code writing messages through IMessageContainer |
| Inputs | Property name and message text |
| Outputs | Populated ModelStateDictionary, Warnings, Informationals |
| Primary components | ModelStateWrapper.AddError, AddWarning, AddInformation |
| Entry point | src/Web.Mvc/Classes/ModelStateWrapper.cs |
Steps¶
AddError— when the same message text already exists on any model-state entry (case-insensitive), replace the message withstring.Emptybefore adding, so the text is displayed once even when several properties are in error; then callmodelState.AddModelError(propertyName, message). The model-state entry is still created, so field-level highlighting still works (BR-37).AddWarning— append only when no case-insensitive duplicate exists inWarnings(BR-38).AddInformation— append only when no case-insensitive duplicate exists inInformationals(BR-38).
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([Message written via IMessageContainer])
Kind{Error, Warning, or Information?}
ErrDup{Duplicate error text?}
ErrBlank[Add with blank message]
ErrFull[Add model error with full text]
WarnDup{Duplicate warning/info?}
Suppress([Suppress duplicate])
Append([Append message])
Start --> Kind
Kind -->|Error| ErrDup
ErrDup -->|Yes| ErrBlank
ErrDup -->|No| ErrFull
Kind -->|Warning/Info| WarnDup
WarnDup -->|Yes| Suppress
WarnDup -->|No| Append
Failure and edge-case behavior¶
- No unexpected failure paths beyond argument-guard exceptions and delegated dependency behavior were identified for this operation.
Related documentation¶
Sources¶
src/Web.Mvc/Classes/ModelStateWrapper.cs