Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obsoleting AddDataAnnotationsValidation and replacing with EnableDataAnnotationsValidation #458

Open
SteveSandersonMS opened this issue Apr 5, 2021 · 1 comment
Labels
6.0.0 Breaking change Documented The breaking change has been published to the .NET Core docs

Comments

@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Apr 5, 2021

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
@SteveSandersonMS
Copy link
Member Author

Please use dotnet/aspnetcore#31536 for questions and discussions.

@aspnet aspnet locked and limited conversation to collaborators Apr 5, 2021
@Rick-Anderson Rick-Anderson added the Documented The breaking change has been published to the .NET Core docs label Apr 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
6.0.0 Breaking change Documented The breaking change has been published to the .NET Core docs
Projects
None yet
Development

No branches or pull requests

2 participants