Skip to content

Obsoleting AddDataAnnotationsValidation and replacing with EnableDataAnnotationsValidation #458

@SteveSandersonMS

Description

@SteveSandersonMS

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    6.0.0Breaking changeDocumentedThe breaking change has been published to the .NET Core docs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions