expressappframework-devexpress-dot-persistent-dot-validation-dot-validator-dot-getservice-x28-system-dot-iserviceprovider-x29.md
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
public static IRuleSet GetService(
IServiceProvider serviceProvider
)
Public Shared Function GetService(
serviceProvider As IServiceProvider
) As IRuleSet
| Name | Type | Description |
|---|---|---|
| serviceProvider | IServiceProvider |
An object that implements the IServiceProvider interface.
|
| Type | Description |
|---|---|
| IRuleSet |
An object that implements the IRuleSet interface.
|
Use this method to access an object that implements the IRuleSet interface. Refer to the IRuleSet topic for more information.
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;
}
}
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.
if (resultsHighlightController != null) {
IRuleSet ruleSet = Validator.GetService(Application.ServiceProvider);
RuleSetValidationResult result = ruleSet.ValidateAllTargets(ObjectSpace, targets, DefaultContexts.Save);
See Also