Skip to content

Commit a2a3ebe

Browse files
committed
upd XPO readme
1 parent aa947aa commit a2a3ebe

1 file changed

Lines changed: 34 additions & 34 deletions

File tree

CS/XPO/Readme.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,18 @@ This example illustrates how to implement a business object with an identifier f
44

55
<img width="890" height="447" alt="sequential-number" src="https://github.com/user-attachments/assets/440955ce-ee90-43b2-b2ae-f63e25fac796" />
66

7+
## Implementation Details
78

8-
## Scenario
9-
10-
This is a variation of the [How to generate a sequential number for a business object within a database transaction](https://www.devexpress.com/Support/Center/p/E2620) XPO example, which was specially adapted for XAF applications.
11-
12-
In particular, for better reusability and smoother integration with standard XAF CRUD Controllers, all required operations to generate sequences are managed within the base persistent class automatically when a persistent object is being saved. This solution consists of several key parts:
13-
14-
* [Sequence](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/SequenceGenerator.cs) and [SequenceGenerator](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/SequenceGenerator.cs) are auxiliary classes that are primarily responsible for generating user-friendly identifiers. 
15-
* [UserFriendlyIdPersistentObject](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/UserFriendlyIdPersistentObject.cs) is a base persistent class that subscribes to XPO's Session events and delegates calls to the core classes above. To get the described functionality in your project, inherit your own business classes from this base class.
16-
17-
Check the original example description first for more information on the demonstrated scenarios and functionality.
9+
Follow the steps below to add this functionality to your project:
1810

19-
## Implementation Details
11+
1. Copy the following files to your project:
2012

21-
1. Copy the [SequenceGenerator](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/SequenceGenerator.cs) and [UserFriendlyIdPersistentObject](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/UserFriendlyIdPersistentObject.cs) files to your project.
13+
* [SequenceGenerator.cs](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/SequenceGenerator.cs) contains classes responsible for generating user-friendly identifiers.
14+
* [UserFriendlyIdPersistentObject.cs](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/UserFriendlyIdPersistentObject.cs) is a base persistent class that subscribes to XPO's Session events and delegates calls to the core classes above. To get the described functionality in your project, inherit your own business classes from this base class.
2215

2316
2. Register the `SequenceGeneratorProvider` scoped service, configure `SequenceGeneratorOptions`, and specify the method that will be used to retrieve the Connection String from the database:
2417

25-
For applications without multi-tenancy:
26-
27-
* ASP.NET Core Blazor (`YourSolutionName\YourSolutionName.Blazor.Server\Startup.cs`)
18+
* **ASP.NET Core Blazor without multi-tenancy** (`YourSolutionName\YourSolutionName.Blazor.Server\Startup.cs`)
2819

2920
```cs{7-12}
3021
public class Startup {
@@ -41,7 +32,7 @@ Check the original example description first for more information on the demonst
4132
});
4233
```
4334

44-
* WinForms (`YourSolutionName\YourSolutionName.Win\Startup.cs`)
35+
* **WinForms without multi-tenancy** (`YourSolutionName\YourSolutionName.Win\Startup.cs`)
4536

4637
```cs{7-12}
4738
//...
@@ -57,10 +48,8 @@ Check the original example description first for more information on the demonst
5748
};
5849
});
5950
```
60-
61-
For multi-tenant applications:
6251

63-
* ASP.NET Core Blazor (`YourSolutionName\YourSolutionName.Blazor.Server\Startup.cs`)
52+
* **ASP.NET Core Blazor multi-tenant applications** (`YourSolutionName\YourSolutionName.Blazor.Server\Startup.cs`)
6453

6554
```cs{7-12}
6655
public class Startup {
@@ -77,7 +66,7 @@ Check the original example description first for more information on the demonst
7766
});
7867
```
7968

80-
* WinForms (`YourSolutionName\YourSolutionName.Win\Startup.cs`)
69+
* **WinForms multi-tenant applications** (`YourSolutionName\YourSolutionName.Win\Startup.cs`)
8170

8271
```cs{7-12}
8372
//...
@@ -94,9 +83,7 @@ Check the original example description first for more information on the demonst
9483
});
9584
```
9685

97-
For applications with Middle Tier Security:
98-
99-
* Middle Tier project (`YourSolutionName.MiddleTier\Startup.cs`):
86+
* **Applications with Middle Tier Security** (`YourSolutionName.MiddleTier\Startup.cs`):
10087

10188
```cs{4-10}
10289
public class Startup
@@ -105,14 +92,13 @@ Check the original example description first for more information on the demonst
10592
services.AddScoped<SequenceGeneratorProvider>();
10693
services.Configure<SequenceGeneratorOptions>(opt => {
10794
opt.GetConnectionString = (serviceProvider) => {
108-
var options = serviceProvider.GetRequiredService<IOptions<DataServerSecurityOptions>>();
109-
return options.Value.ConnectionString;
95+
return serviceProvider.GetRequiredService<IConnectionStringProvider>().GetConnectionString();
11096
};
11197
});
11298
```
11399

114-
3. Inherit your business classes to which you want to add sequential numbers from the module's `UserFriendlyIdPersistentObject` class. Declare a calculated property that uses the `SequenceNumber` property of the base class to produce a string identifier according to the required format:
115-
100+
3. To add sequential numbers to your business class, inherit it from the `UserFriendlyIdPersistentObject` class. Declare a calculated property that utilizes the base class's `SequenceNumber` to generate a string identifier in the desired format.
101+
116102
```cs
117103
public class Contact : GenerateUserFriendlyId.Module.BusinessObjects.UserFriendlyIdPersistentObject {
118104
[PersistentAlias("Concat('C',PadLeft(ToStr(SequentialNumber),6,'0'))")]
@@ -122,8 +108,8 @@ Check the original example description first for more information on the demonst
122108
123109
```
124110

125-
4. Separate sequences are generated for each business object type. If you need to create multiple sequences for the same type, based on values of other object properties, override the `GetSequenceName` method and return the constructed sequence name. The `Address` class in this example uses separate sequences for each `Province` as follows:
126-
111+
4. Separate sequences are created for each business object type. To generate multiple sequences for the same type based on other properties, override `GetSequenceName` to return a custom sequence name. In this example, the `Address` class uses different sequences for each `Province`.
112+
127113
```cs
128114
protected override string GetSequenceName() {
129115
return string.Concat(ClassInfo.FullName, "-", Province.Replace(" ", "_"));
@@ -132,8 +118,12 @@ Check the original example description first for more information on the demonst
132118

133119
## Additional Information
134120

135-
1. In application with the Security System, the newly generated sequence number will appear in the Detail View only after a manual refresh (in other words, it will be empty right after saving a new record), because the sequence is generated on the server side only and is not passed to the client. See the following section of the **Auto-Generate Unique Number Sequence** KB article: [Refresh the Identifier field value in UI](https://docs.devexpress.com/eXpressAppFramework/403605/business-model-design-orm/unique-auto-increment-number-generation#refresh-the-identifier-field-value-in-the-ui).
136-
2. You can specify the initial sequence value manually. For this purpose, either edit the **Sequence** table in the database or use the [standard XPO/XAF](https://docs.devexpress.com/eXpressAppFramework/113711/data-manipulation-and-business-logic/create-read-update-and-delete-data) techniques to manipulate the `Sequence` objects. For example, you can use the following code:
121+
122+
123+
124+
1. In applications with the Security System, a new sequence number appears in the Detail View only after a manual refresh because it is generated server-side and not immediately sent to the client. For more details, see the following help topic: [Refresh the Identifier Field Value in the UI](https://docs.devexpress.com/eXpressAppFramework/403605/business-model-design-orm/unique-auto-increment-number-generation#refresh-the-identifier-field-value-in-the-ui).
125+
126+
2. You can manually set the initial sequence value by editing the `Sequence` table in the database or using [standard XPO/XAF](https://docs.devexpress.com/eXpressAppFramework/113711/data-manipulation-and-business-logic/create-read-update-and-delete-data) methods to modify `Sequence` objects. For instance, you can use the following code:
137127

138128
```cs
139129
using(IObjectSpace os = Application.CreateObjectSpace(typeof(Sequence))) {
@@ -142,8 +132,18 @@ Check the original example description first for more information on the demonst
142132
os.CommitChanges();
143133
}
144134
```
145-
135+
136+
## Files to Review
137+
138+
* [SequenceGenerator.cs](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/SequenceGenerator.cs)
139+
* [UserFriendlyIdPersistentObject.cs](SequenceGenerator/SequenceGenerator.Module/SequenceClasses/UserFriendlyIdPersistentObject.cs)
140+
* [SequenceGenerator.Blazor.Server/Startup.cs](SequenceGenerator/SequenceGenerator.Blazor.Server/Startup.cs)
141+
* [SequenceGenerator.Win/Startup.cs](SequenceGenerator/SequenceGenerator.Win/Startup.cs)
142+
146143
## Documentation
147-
148-
* [Auto-Generate Unique Number Sequence](https://www.devexpress.com/Support/Center/p/T567184)
149144

145+
* [Auto-Generate Unique Number Sequence](https://docs.devexpress.com/eXpressAppFramework/403605/business-model-design-orm/unique-auto-increment-number-generation)
146+
147+
## More Examples
148+
149+
* [How to generate a sequential number for a business object within a database transaction](https://supportcenter.devexpress.com/ticket/details/e2620/how-to-generate-a-sequential-number-for-a-business-object-within-a-database-transaction)

0 commit comments

Comments
 (0)