Skip to content

Commit 09fb56e

Browse files
ReubenBondCopilotgewarren
authored
Clarify Orleans constructor migration guidance (#52870)
* Clarify Orleans constructor migration guidance Update the Orleans migration guide and breaking changes summary to distinguish serializer constructors from generated activator constructors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Refine Orleans constructor migration docs Clarify that the replacement attributes are for dependency injection scenarios and update the migration example to use an injected service instead of serialized data. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Mark injected dependency as non-serialized Update the Orleans migration guide example so the injected dependency property is marked with [field: NonSerialized] and does not trigger analyzer warnings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Clarify OrleansConstructor sample comment Update the Orleans migration guide sample to note that [OrleansConstructor] was obsolete and ignored. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update docs/orleans/migration-guide.md Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> * Update docs/orleans/includes/orleans-10-breaking-changes.md Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
1 parent 96de41f commit 09fb56e

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

docs/orleans/includes/orleans-10-breaking-changes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
| `CancelRequestOnTimeout` default changed | Behavioral | Explicitly set to `true` if needed |
1111
| ADO.NET provider requires `Microsoft.Data.SqlClient` | Compile/Runtime error | Replace `System.Data.SqlClient` package |
1212
| `[Unordered]` attribute obsoleted | Warning | Remove attribute (has no effect) |
13-
| `OrleansConstructorAttribute` obsoleted | Warning | Use <xref:Orleans.GeneratedActivatorConstructorAttribute> |
13+
| `OrleansConstructorAttribute` obsoleted | Warning | Use <xref:Orleans.GeneratedActivatorConstructorAttribute> or <xref:Microsoft.Extensions.DependencyInjection.ActivatorUtilitiesConstructorAttribute> only for constructors that require dependency injection, not for serialized data properties |
1414
| `RegisterTimer` obsoleted | Warning | Use <xref:Orleans.GrainBaseExtensions.RegisterGrainTimer*> |

docs/orleans/migration-guide.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,45 @@ public interface IMyGrain : IGrainWithStringKey
156156

157157
### Breaking change: `OrleansConstructorAttribute` obsoleted
158158

159-
The `OrleansConstructorAttribute` has been obsoleted. Use <xref:Orleans.GeneratedActivatorConstructorAttribute> or `ActivatorUtilitiesConstructorAttribute` instead to specify which constructor the serializer should use.
159+
The `OrleansConstructorAttribute` has been obsoleted. Use <xref:Orleans.GeneratedActivatorConstructorAttribute> or <xref:Microsoft.Extensions.DependencyInjection.ActivatorUtilitiesConstructorAttribute> instead. Only apply these attributes to constructors that require services to be injected via dependency injection. Don't use them to indicate how Orleans should set serialized data properties or fields.
160160

161161
```csharp
162+
public interface IMyDependency
163+
{
164+
}
165+
162166
// Orleans 7.x
163167
[GenerateSerializer]
164168
public class MyClass
165169
{
166-
[OrleansConstructor] // Obsolete
167-
public MyClass(string value) { }
170+
[Id(0)]
171+
public string Value { get; set; }
172+
173+
[OrleansConstructor] // Obsolete and ignored
174+
public MyClass(IMyDependency dependency)
175+
{
176+
Dependency = dependency;
177+
}
178+
179+
[field: NonSerialized]
180+
public IMyDependency Dependency { get; }
168181
}
169182

170183
// Orleans 10.0
171184
[GenerateSerializer]
172185
public class MyClass
173186
{
187+
[Id(0)]
188+
public string Value { get; set; }
189+
174190
[GeneratedActivatorConstructor]
175-
public MyClass(string value) { }
191+
public MyClass(IMyDependency dependency)
192+
{
193+
Dependency = dependency;
194+
}
195+
196+
[field: NonSerialized]
197+
public IMyDependency Dependency { get; }
176198
}
177199
```
178200

0 commit comments

Comments
 (0)