CSLA 10 is a major release and so there are a number of breaking changes.
In this document I'll try to highlight the most common changes required when upgrading your codebase from CSLA 9 to CSLA 10.
If you are upgrading from a version of CSLA prior to 8, you should review the Upgrading to CSLA 9 document, as most of its contents are relevant. This document only covers the changes from CSLA 9 to CSLA 10.
TBD
The constructor has changed and now expects an IOptions<RevalidatingInterceptorOptions> instance. With this new options object it is now possible to skip the revalidation of business rules during a Delete operation.
To configure the new options we are using the .Net Options pattern.
services.Configure<RevalidatingInterceptorOptions>(opts =>
{
opts.IgnoreDeleteOperation = true;
});A new API is added to make it possible to handle exceptions thrown by asynchronous rules.
The new interface to implement is Csla.Rules.IUnhandledAsyncRuleExceptionHandler which has two methods
-
bool CanHandle(Exception, IBusinessRuleBase)- to decide whether this exception should be handled or not
-
ValueTask Handle(Exception, IBusinessRuleBase, IRuleContext)- to handle the exception when
CanHandle(...) == trueWith these methods you can now decide whether to handle the exception and how or let the exception be unobserved bubble up and potentially cause a crash.
- to handle the exception when
You can register your implementation in two ways
- Just add the implementation to your service collection
services.AddScoped<IUnhandledAsyncRuleExceptionHandler, YourImplementation>() - Use
services.AddCsla(o => o.UseUnhandledAsyncRuleExceptionHandler<YourImplementation>());. The handler is registered as scoped.
The default is still no handling of any exception thrown in an asynchronous rule.
CSLA 10 supports the use of nullable reference types in your code. This means that you can use the #nullable enable directive in your code and the compiler will now tell you where CSLA does not expect any null values or returns null.
Supporting nullable types means that some APIs have changed to support nullable types.
- Many methods now throw an
ArgumentNullExceptioninstead of aNullReferenceException. That means typically the methods didn't work so far withnullanyway - The
UserandPrincipalproperties ofApplicationContextno longer return null Csla.Configuration.ConfigurationManager.AppSettingsand.ConnectionStringsare no longer settableCsla.Core.LoadManager.AsyncLoadException.Propertyproperty set removed. It can now only be set by the constructorCsla.Core.AddedNewEventArgs<T>default constructor removedCsla.Reflection.LateBoundObject(Type objectType)constructor removed (hasn't worked so far anyway)Csla.Core.UndoExceptionconstructors now throwArgumentNullExceptionon necessary parameters and all public fields changed to readonly propertiesCsla.Data.ObjectAdapter.Fill(DataTable dt, object source)throws anArgumentNullExceptionfor source instead ofArgumentException.Csla.Reflection.ServiceProviderMethodInfo- Now has a constructor requiring a
MethodInfoparameter - Property
MethodInfoproperty set removed and replaced by the constructor
- Now has a constructor requiring a
Csla.Reflection.DynamicMemberHandledoes not accept anynullparameters now. That includes having no get/set for a property/field.Csla.Rules.BrokenRulecan not be instantiated by user code. It wasn't useable before because all property setters were internal.Csla.Rules.BrokenRulesCollectiondoes not accept any null, empty or white space values for methods which accepts a string for a property name.Csla.Rules.IRuleContext.Add*Result(...)methods now throw anArgumentExceptionwhen the providedstring descriptionisIsNullOrWhiteSpace.Csla.Security.IAuthorizeReadWriteall methodsArgumentNullExceptionare now documented.Csla.Web.Mvc.CslaModelBindernow needs anApplicationContextin it's constructor.AddAspNetCore()configuration method now adds the necessary services to support resolvingCslaModelBinderfrom the DI containerCsla.Serialization.Mobile.SerializationInfo- Now has a constructor requiring
int referenceIdandstring typeName - Property
ReferenceIdandTypeNameproperty set removed and replaced by the constructor
- Now has a constructor requiring
Csla.Server.InterceptArgs- Now as two new constructors requiring necessary parameters
- Property set for required parameters removed
Csla.Server.EmptyCriteria- Public constructor removed (now private). Instead use
Csla.Server.EmptyCriteria.Instance.
- Public constructor removed (now private). Instead use
Csla.Server.ObjectFactory- Protected methods now guard against
nullobjects
- Protected methods now guard against
SessionMessagenow inherits fromMobileObjectinstead ofCommandBase.DataPortalResponsenow uses[AutoSerializable]to auto implementIMobileObjectinstead of inheriting fromReadOnlyBase.UpdateRequestnow uses[AutoSerializable]to auto implementIMobileObjectinstead of inheriting fromReadOnlyBase.
Csla.Server.DataPortalconstructor changed.- Removed unused parameters:
IDataPortalActivator activator,IDataPortalExceptionInspector exceptionInspector.
- Removed unused parameters:
Csla.Rules.BusinessRulesconstructor changed.- New parameter
IUnhandledAsyncRuleExceptionHandleradded to support the new asynchronous rule exception handling.
- New parameter