Skip to content

Commit e0573f1

Browse files
More upgrade documentation added
1 parent 3a1ef13 commit e0573f1

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

docs/Upgrading to CSLA 10.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ services.Configure<RevalidatingInterceptorOptions>(opts =>
2121
});
2222
```
2323

24-
## Exception from asynchronous rules
24+
## New exception handler for asynchronous rules
2525
A new API is added to make it possible to handle exceptions thrown by asynchronous rules.
2626
The new interface to implement is `Csla.Rules.IUnhandledAsyncRuleExceptionHandler` which has two methods
2727
* `bool CanHandle(Exception, IBusinessRuleBase)`
@@ -33,13 +33,64 @@ With these methods you can now decide whether to handle the exception and how or
3333

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

3839
The _default_ is still no handling of any exception thrown in an asynchronous rule.
3940

41+
## `IDataPortal` / `IChildDataPortal` breaking changes
42+
Both interfaces `IDataPortal` and `IChildDataPortal` got the following changes to improve trimming support:
43+
* Returning `ICslaObject`instead of `object`.
44+
* `Update`/`Execute` now expect an `ICslaObject` parameter instead of `object`.
45+
46+
## `InjectAttribute` - AllowNull addition
47+
The `InjectAttribute` got a new property called `AllowNull`. This property controls whether csla will use `GetService` or `GetRequiredService`.
48+
With `AllowNull == true` means it's using `GetService` which can return a `null` for a requested object.
49+
With `AllowNull == false` means it's using `GetRequiredService` which can not return `null` and will cause an exception.
50+
Furthermore you can ignore the new property if you are working with the nullable reference types. In that case the `AllowNull` is implicitly declared by your parameter declaration. For example:
51+
```csharp
52+
#nullable enable // or set by your project
53+
54+
[Fetch]
55+
private void Fetch([Inject] IService1 service1, [Inject] IService2? service2, [Inject(AllowNull = true)] IService3 service3)
56+
{
57+
// ...
58+
}
59+
```
60+
In the example above `service1` will be resolved with `GetRequiredService` while `service2` will be resolved with `GetService`. You can also set `AllowNull` which will override the nullable reference annotation. The other way around `[Inject(AllowNull = false)] IService4? service4` will _not_ change the parameter to be not-null. In this case the annotation takes precedence.
61+
62+
## `IDataErrorInfo` & `INotifyDataErrorInfo` extension points added
63+
The `BusinessBase` implementation of [IDataErrorInfo](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.idataerrorinfo?view=net-10.0) and [INotifyDataErrorInfo](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifydataerrorinfo?view=net-10.0) now provide `virtual` methods to change the behavior.
64+
`IDataErrorInfo`
65+
* `IDataErrorInfo.Error`-> `protected virtual string GetDataErrorInfoError()`
66+
* `IDataErrorInfo.Item[string]`-> `protected virtual string GetDataErrorInfoIndexerError(string)`
67+
68+
`INotifyDataErrorInfo`
69+
* `INotifyDataErrorInfo.GetErrors(string?)` -> `protected virtual IEnumerable GetNotifyDataErrorInfoGetErrors(string?)`
70+
* `INotifyDataErrorInfo.HasErrors` -> `protected virtual bool GetNotifyDataErrorInfoHasErrors()`
4071

4172
## Nullable Reference Types
4273

74+
### Important breaking change/note
75+
Due to this change it is **not** possible anymore to assign a csla property in a constructor. Be it a command or a business object.
76+
For example
77+
```csharp
78+
public class FooCommand : CommandBase<FooCommand> {
79+
public static PropertyInfo<string> DataProperty = RegisterProperty<string>(nameof(Data));
80+
public string Data
81+
{
82+
get { return GetProperty(DataProperty); }
83+
set { SetProperty(DataProperty, value); }
84+
}
85+
86+
public FooCommand() {
87+
Data = ""; // This will now result in an ArgumentNullException because the needed ApplicationContext is not available yet.
88+
}
89+
}
90+
```
91+
92+
### Explanation
93+
4394
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`.
4495

4596
Supporting nullable types means that some APIs have changed to support nullable types.

0 commit comments

Comments
 (0)