Validator.GetService(IServiceProvider) Method
Takes an IServiceProvider instance as a parameter and returns an instance of IRuleSet.
Namespace: DevExpress.Persistent.Validation
Assembly: DevExpress.Persistent.Base.v25.2.dll
NuGet Package: DevExpress.Persistent.Base
Declaration
Parameters
| Name | Type | Description |
|---|---|---|
| serviceProvider | IServiceProvider | An object that implements the |
Returns
| Type | Description |
|---|---|
| IRuleSet | An object that implements the |
Remarks
Use this method to access an object that implements the IRuleSet interface. Refer to the IRuleSet topic for more information.
Example
The following code snippet demonstrates how to use the Validator.GetService method to access an IRuleSet instance and use it to trigger validation against a specific object and context, and then handle the result:
File: MySolution.Module.Controllers.MyController.cs
using DevExpress.Persistent.Validation;
// ...
namespace MySolution.Module.Controllers;
public partial class MyController : ViewController {
// ...
protected override void OnActivated() {
base.OnActivated();
RuleSetValidationResult result = Validator.GetService(Application.ServiceProvider).ValidateTarget(
View.ObjectSpace,
View.CurrentObject,
"MyContext"
);
if (result.ValidationOutcome > ValidationOutcome.Information)
((Contact)View.CurrentObject).Notes += "[Validation Error] " + result.Results[0].ErrorMessage;
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetService(IServiceProvider) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.