Suppress Object Level Business rules (not associated with properties) #3671
-
We have three methods of suppressing property level rules (as discussed on page 92 of Using Csla objects book). ((Csla.Core.ICheckRules)_customer).SuppressRuleChecking();
try
{
// set properties here without executing
// any rules
}
finally
{
((Csla.Core.ICheckRules)_customer).ResumeRuleChecking();
((Csla.Core.ICheckRules)_customer).CheckRules();
} We found out that when we create the object by calling DataPortal.Create, object levels rules are executed while property rules are added but not 'executed'. Kind Regards |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 10 replies
-
That was easy : ) |
Beta Was this translation helpful? Give feedback.
-
Here's a basic test on which we can build a discussion. I'm not sure where you are suppressing rules? If the using Csla;
using Csla.Configuration;
using Csla.Rules;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddCsla();
var provider = services.BuildServiceProvider();
var portal = provider.GetRequiredService<IDataPortal<PersonEdit>>();
var obj = portal.Create();
[Serializable]
public class PersonEdit : BusinessBase<PersonEdit>
{
public static readonly PropertyInfo<string> NameProperty = RegisterProperty<string>(nameof(Name));
public string Name
{
get => GetProperty(NameProperty);
set => SetProperty(NameProperty, value);
}
protected override void AddBusinessRules()
{
base.AddBusinessRules();
BusinessRules.AddRule(new TypeRule());
BusinessRules.AddRule(new PropertyRule { PrimaryProperty = NameProperty });
}
[Create]
private void Create()
{
Console.WriteLine(nameof(Create));
//BusinessRules.CheckRules();
}
}
public class TypeRule : BusinessRule
{
protected override void Execute(IRuleContext context)
{
Console.WriteLine(nameof(TypeRule));
}
}
public class PropertyRule : BusinessRule
{
protected override void Execute(IRuleContext context)
{
Console.WriteLine(nameof(PropertyRule));
}
} |
Beta Was this translation helpful? Give feedback.
-
@rockfordlhotka Thank you Sir. to get the same behavior as above? Kind Regards |
Beta Was this translation helpful? Give feedback.
-
@rockfordlhotka I noticed that if we assign a priority of -10 to PropertyRule and a priority of 10 to TypeRule, TypeRule is still executed first (if we don't comment out the line BusinessRules.CheckRules(); in Create). Kind Regards |
Beta Was this translation helpful? Give feedback.
Here's a basic test on which we can build a discussion. I'm not sure where you are suppressing rules?
If the
CheckRules
method is not calling in the create operation, no rules run. if it is called in the create operation then the type and property rules run.