-
Notifications
You must be signed in to change notification settings - Fork 81
Description
Obsoleting AddDataAnnotationsValidation and replacing with EnableDataAnnotationsValidation
The extension method EditContextDataAnnotationsExtensions.AddDataAnnotationsValidation is being marked as obsolete. Developers should use the new extension method EditContextDataAnnotationsExtensions.EnableDataAnnotationsValidation instead.
The only difference between these two APIs is in their return values:
EditContext AddDataAnnotationsValidation(this EditContext editContext) { ... }
IDisposable EnableDataAnnotationsValidation(this EditContext editContext) { ... }Version introduced
6.0
Old behavior
The older API returns its EditContext (as a kind of fluent API).
New behavior
The new API returns an IDisposable whose disposal can be used to remove the data annotations validation support from the EditContext.
Reason for change
There are cases where it's desirable to remove the data annotations validation support after adding it. This was not possible with the older API because there was no place to store the internal event subscriptions. The new API returns an object that holds the state necessary to remove data annotations validation support on disposal.
Recommended action
This does not affect most applications, because most applications do not call this directly anyway. Most applications instead use the <DataAnnotationsValidator> component, and do not need to be changed. The use of the extension methods discussed here is a rare and advanced case.
However, if you do call editContext.AddDataAnnotationsValidation(), then replace that call with editContext.EnableDataAnnotationsValidation(). Optionally, captured the new returned IDisposable and dispose it if you later wish to undo the effects of the call.
Category
ASP.NET
Affected APIs
EditContextDataAnnotationsExtensions.AddDataAnnotationsValidation(EditContext)
Issue metadata
- Issue type: breaking-change