Skip to content

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

  1. AddError — when the same message text already exists on any model-state entry (case-insensitive), replace the message with string.Empty before adding, so the text is displayed once even when several properties are in error; then call modelState.AddModelError(propertyName, message). The model-state entry is still created, so field-level highlighting still works (BR-37).
  2. AddWarning — append only when no case-insensitive duplicate exists in Warnings (BR-38).
  3. AddInformation — append only when no case-insensitive duplicate exists in Informationals (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.

Sources

  • src/Web.Mvc/Classes/ModelStateWrapper.cs