Skip to content

Commit 00e3496

Browse files
CSLA 10 upgrade doc (#4745)
* Clean up CSLA 10 upgrade doc * Merge docs
1 parent 753960c commit 00e3496

File tree

1 file changed

+111
-5
lines changed

1 file changed

+111
-5
lines changed

docs/Upgrading to CSLA 10.md

Lines changed: 111 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ If you are upgrading from a version of CSLA prior to 8, you should review the [U
88

99
## Platform Support
1010

11-
TBD
11+
CSLA 10 continues to support .NET Framework 4.6.2 and later, as well as modern .NET versions. CSLA 10 adds support for .NET 10.
1212

1313
## RevalidatingInterceptor
1414

1515
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.
1616
To configure the new options we are using the .Net [Options pattern](https://learn.microsoft.com/en-us/dotnet/core/extensions/options).
17+
1718
```csharp
1819
services.Configure<RevalidatingInterceptorOptions>(opts =>
1920
{
@@ -24,26 +25,30 @@ services.Configure<RevalidatingInterceptorOptions>(opts =>
2425
## New exception handler for asynchronous rules
2526
A new API is added to make it possible to handle exceptions thrown by asynchronous rules.
2627
The new interface to implement is `Csla.Rules.IUnhandledAsyncRuleExceptionHandler` which has two methods
27-
* `bool CanHandle(Exception, IBusinessRuleBase)`
28-
* to decide whether this exception should be handled or not
2928

29+
* `bool CanHandle(Exception, IBusinessRuleBase)`
30+
* to decide whether this exception should be handled or not
3031
* `ValueTask Handle(Exception, IBusinessRuleBase, IRuleContext)`
31-
* to handle the exception when `CanHandle(...) == true`
32+
* to handle the exception when `CanHandle(...) == true`
33+
3234
With 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.
3335

3436
You can register your implementation in two ways
37+
3538
* Just add the implementation to your service collection `services.AddScoped<IUnhandledAsyncRuleExceptionHandler, YourImplementation>()`
3639
* Note: This has to be registered _after_ csla is added to the service collection.
3740
* Use `services.AddCsla(o => o.UseUnhandledAsyncRuleExceptionHandler<YourImplementation>());`. The handler is registered as scoped.
3841

3942
The _default_ is still no handling of any exception thrown in an asynchronous rule.
4043

4144
## `IDataPortal` / `IChildDataPortal` breaking changes
45+
4246
Both interfaces `IDataPortal` and `IChildDataPortal` got the following changes to improve trimming support:
4347
* Returning `ICslaObject`instead of `object`.
4448
* `Update`/`Execute` now expect an `ICslaObject` parameter instead of `object`.
4549

4650
## `InjectAttribute` - AllowNull addition
51+
4752
The `InjectAttribute` got a new property called `AllowNull`. This property controls whether csla will use `GetService` or `GetRequiredService`.
4853
With `AllowNull == true` means it's using `GetService` which can return a `null` for a requested object.
4954
With `AllowNull == false` means it's using `GetRequiredService` which can not return `null` and will cause an exception.
@@ -128,8 +133,109 @@ Supporting nullable types means that some APIs have changed to support nullable
128133
* `UpdateRequest` now uses `[AutoSerializable]` to auto implement `IMobileObject` instead of inheriting from `ReadOnlyBase`.
129134

130135

136+
## `ViewModel<T>.SaveAsync` and `CslaDataProvider.Refresh` return `Task`
137+
138+
The `ViewModel<T>.SaveAsync(object sender, ExecuteEventArgs e)` method and `CslaDataProvider.Refresh<T>(Func<Task<T>> factory)` method now return `Task` instead of `async void`. This is a breaking change for any code that calls these methods directly.
139+
140+
If you were calling these methods without awaiting them, you will now need to handle the returned `Task` appropriately:
141+
142+
```csharp
143+
// Before (async void - fire and forget)
144+
viewModel.SaveAsync(sender, e);
145+
146+
// After (returns Task - must be handled)
147+
await viewModel.SaveAsync(sender, e);
148+
// or if you truly want fire-and-forget behavior:
149+
_ = viewModel.SaveAsync(sender, e);
150+
```
151+
152+
## OpenTelemetry Instrumentation
153+
154+
CSLA 10 adds OpenTelemetry instrumentation for the data portal. A new `OpenTelemetryDashboard` class provides metrics for data portal operations including total calls, completed calls, failed calls, and call duration.
155+
156+
To enable OpenTelemetry metrics, register the dashboard:
157+
158+
```csharp
159+
services.AddCsla(o => o.DataPortal(dp =>
160+
dp.RegisterDashboard<OpenTelemetryDashboard>()));
161+
```
162+
163+
The metrics integrate with standard OpenTelemetry consumers such as Prometheus, Grafana, Azure Monitor, and .NET Aspire dashboards.
164+
165+
## Virtual `Deserialized` Method
166+
167+
A new `protected virtual void Deserialized()` method has been added to `BusinessBase`, `ExtendedBindingList`, and `ObservableBindingList`. This method is called after deserialization completes and provides an extension point for custom post-deserialization logic.
168+
169+
```csharp
170+
public class MyBusinessObject : BusinessBase<MyBusinessObject>
171+
{
172+
protected override void Deserialized()
173+
{
174+
base.Deserialized();
175+
// Custom post-deserialization logic here
176+
}
177+
}
178+
```
179+
180+
## `IMobileObjectMetastate` Interface
181+
182+
A new `IMobileObjectMetastate` interface has been added to `Csla.Serialization.Mobile`. This interface is intended for developers creating custom serializers as an alternative to `MobileFormatter`.
183+
184+
The interface defines two methods:
185+
* `byte[] GetMetastate()` - Gets lightweight serialization of field values (metastate) without child object references
186+
* `void SetMetastate(byte[] metastate)` - Sets the metastate from a byte array
187+
188+
This interface is implemented on `MobileObject`, `MobileBindingList`, and `ReadOnlyListBase`. The metastate is intended for transitory data serialization, not long-term storage.
189+
190+
## Binary Serialization for Metastate
191+
192+
The internal serialization of metastate data now uses binary serialization instead of JSON. This provides improved performance for data portal operations. Since CSLA requires the same version on both ends of a network connection, this change is transparent to most applications.
193+
194+
## Principal Caching Removed
195+
196+
`ApplicationContextManager.GetUser()` no longer caches the current principal. It now always retrieves the principal from `Thread.CurrentPrincipal`. This improves behavior in multi-threaded scenarios and prevents stale principal references.
197+
198+
If your code relied on the previous caching behavior, you may need to review your authorization logic.
199+
200+
## `TransactionIsolationLevel.Snapshot`
201+
202+
A new `Snapshot` option has been added to the `TransactionIsolationLevel` enum. This allows use of snapshot isolation when using the `Transactional` attribute:
203+
204+
```csharp
205+
[Transactional(TransactionIsolationLevel.Snapshot)]
206+
private void DataPortal_Update()
207+
{
208+
// Update logic with snapshot isolation
209+
}
210+
```
211+
212+
## `FriendlyName` Property on XAML `PropertyInfo`
213+
214+
The `Csla.Xaml.PropertyInfo` component now includes a `FriendlyName` property that can be used to display a user-friendly property name in WPF/XAML applications.
215+
216+
## `RuleContextModes` for Rule Execution Control
217+
218+
A new `RuleContextModes` enum has been added to provide control over when rules execute. The `RuleContext` now includes an `ExecuteContext` property with the following flags:
219+
* `Any` - Rule executes in any context
220+
* `CheckRules` - Rule executes during CheckRules calls
221+
* `CheckObjectRules` - Rule executes during CheckObjectRules calls
222+
* `PropertyChanged` - Rule executes when the property changes
223+
* `AsAffectedProperty` - Rule executes as an affected property
224+
225+
## `ScanForDataAnnotations` Configuration Option
226+
227+
A new configuration option `CslaOptions.ScanForDataAnnotations(bool flag)` allows disabling the automatic scanning for DataAnnotations attributes on business objects.
228+
229+
```csharp
230+
services.AddCsla(o => o.ScanForDataAnnotations(false));
231+
```
232+
233+
> **Caution:** Setting this to `false` completely disables DataAnnotations attribute support within CSLA. Only use this option if you are certain your application does not use DataAnnotations attributes for validation and you need the performance benefit of skipping the attribute scan.
234+
131235
## Breaking changes
236+
132237
* `Csla.Server.DataPortal` constructor changed.
133238
* Removed unused parameters: `IDataPortalActivator activator`, `IDataPortalExceptionInspector exceptionInspector`.
134239
* `Csla.Rules.BusinessRules` constructor changed.
135-
* New parameter `IUnhandledAsyncRuleExceptionHandler` added to support the new asynchronous rule exception handling.
240+
* New parameter `IUnhandledAsyncRuleExceptionHandler` added to support the new asynchronous rule exception handling.
241+

0 commit comments

Comments
 (0)