Skip to content

Commit 5bf2930

Browse files
authored
Merge pull request #6995 from umbraco/advanced
Updated UI Builder Advanced section articles
2 parents 22c933e + 714ee4d commit 5bf2930

File tree

5 files changed

+185
-97
lines changed

5 files changed

+185
-97
lines changed
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
---
2-
description: Configuring encrypted properties in Umbraco UI Builder, the backoffice UI builder for Umbraco.
2+
description: Configuring and using encrypted properties in Umbraco UI Builder to securely store sensitive data.
33
---
44

55
# Encrypted Properties
66

7-
If needed to collect sensitive information in a collection but don't want to persist in a plain text format to the data storage mechanism. Umbraco UI Builder can help with this by allowing you to define properties as encrypted. After which any time the value is persisted or retrieved from persistence, Umbraco UI Builder will automatically encrypt and decrypt the value.
7+
Umbraco UI Builder allows encrypting properties to store sensitive information securely. When a property is marked as encrypted, its value is automatically encrypted before storage and decrypted upon retrieval.
88

99
{% hint style="info" %}
10-
Umbraco UI Builder uses the `IDataProtectionProvider` instance registered in the DI container to perform its encryption/decryption. If you need to change the encryption algorithm, you should replace the `IDataProtectionProvider` instance in the DI container.
10+
Umbraco UI Builder uses the `IDataProtectionProvider` instance registered in the DI container for encryption and decryption. To modify the encryption algorithm, replace the `IDataProtectionProvider` instance in the DI container.
1111
{% endhint %}
1212

13-
## Defining encrypted properties
13+
## Defining Encrypted Properties
1414

15-
### **AddEncryptedProperty(Lambda encryptedPropertyExpression) : CollectionConfigBuilder<TEntityType>**
15+
### Using the `AddEncryptedProperty()` Method
1616

17-
Adds the given property to the encrypted properties collection. Property must be of type `String`. When set, the property will be encrypted/decrypted on write/read respectively.
17+
Encrypts the specified property. The property must be of type `String`. The value is encrypted before storage and decrypted when retrieved.
18+
19+
#### Method Syntax
20+
21+
```csharp
22+
AddEncryptedProperty(Lambda encryptedPropertyExpression) : CollectionConfigBuilder<TEntityType>
23+
```
24+
25+
#### Example
1826

1927
````csharp
20-
// Example
2128
collectionConfig.AddEncryptedProperty(p => p.Secret);
2229
````

15/umbraco-ui-builder/advanced/events.md

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
---
2-
description: Configuring event handlers in Umbraco UI Builder, the backoffice UI builder for Umbraco.
2+
description: Configuring event handlers in Umbraco UI Builder.
33
---
44

55
# Events
66

7-
Umbraco UI Builder fires a number of notification events during regular operation to allow for extending of the default behaviour.
7+
Umbraco UI Builder triggers different notification events during operation, allowing customization of default behavior.
88

9-
## Registering event handlers
9+
## Registering Event Handlers
1010

11-
Umbraco UI Builder uses the same [Notification Mechanism built into Umbraco v9+](../../umbraco-cms/fundamentals/code/subscribing-to-notifications.md) and so uses the same registration process. First you will need to define a notification event handler for the event you wish to handle like below:
11+
Umbraco UI Builder follows the [Umbraco Notification mechanism](../../umbraco-cms/fundamentals/code/subscribing-to-notifications.md) for event registration.
12+
13+
Define a notification event handler for the target event:
1214

1315
```csharp
1416
public class MyEntitySavingEventHandler : INotificationHandler<EntitySavingNotification> {
@@ -21,7 +23,7 @@ public class MyEntitySavingEventHandler : INotificationHandler<EntitySavingNoti
2123
}
2224
```
2325

24-
Then register your event handler in the `Program.cs` file like below:
26+
Register the event handler in `Program.cs`:
2527

2628
```csharp
2729
builder.CreateUmbracoBuilder()
@@ -33,15 +35,15 @@ builder.CreateUmbracoBuilder()
3335
.Build();
3436
```
3537

36-
## Repository events
38+
## Repository Events
39+
40+
### Using the `EntitySavingNotification()`
3741

38-
### **EntitySavingNotification**
42+
Triggers when `Save` is called before persisting the entity. The notification contains an `Entity` property with `Before` and `After` values, providing access to the previous and updated entities. Modify the `After` entity to persist changes. If the `Cancel` property of the notification is set to `true` then the save operation will be canceled and no changes will be saved.
3943

40-
Raised when the repository `Save` method is called and before the entity has been persisted. The notification contains an `Entity` property with `Before` and `After` inner properties. These properties provide access to a copy of the currently persisted entity (or null if a new entity) and the updated entity that´s saved.
41-
Changes can be made to the `After` entity and they will be persisted as part of the save operation. If the `Cancel` property of the notification is set to `true` then the save operation will be canceled and no changes will be saved.
44+
#### Example
4245

4346
```csharp
44-
// Example
4547
public class MyEntitySavingEventHandler : INotificationHandler<EntitySavingNotification> {
4648

4749
public void Handle(EntitySavingNotification notification)
@@ -53,14 +55,15 @@ public class MyEntitySavingEventHandler : INotificationHandler<EntitySavingNoti
5355
}
5456

5557
}
56-
````
58+
```
5759

58-
### **EntitySavedNotification**
60+
### Using the `EntitySavedNotification()`
5961

60-
Raised when the repository `Save` method is called and after the entity has been persisted. The notification contains an `Entity` property with `Before` and `After` inner properties. These properties provide access to a copy of the previously persisted entity (or null if a new entity) and the updated entity that´s saved.
62+
Triggers when the repository `Save` method is called and after the entity has been persisted. The notification contains an `Entity` property with `Before` and `After` inner properties. These properties provide access to a copy of the previously persisted entity (or null if a new entity) and the updated entity that´s saved.
6163

62-
````csharp
63-
// Example
64+
#### Example
65+
66+
```csharp
6467
public class MyEntitySavedEventHandler : INotificationHandler<EntitySavedNotification> {
6568

6669
public void Handle(EntitySavedNotification notification)
@@ -74,12 +77,13 @@ public class MyEntitySavedEventHandler : INotificationHandler<EntitySavedNotifi
7477
}
7578
```
7679

77-
### **EntityDeletingNotification**
80+
### Using the `EntityDeletingNotification()`
81+
82+
Triggers when the repository `Delete` method is called and **before** the entity is deleted. The notification contains an `Entity` property providing access to a copy of the entity about to be deleted. If the `Cancel` property of notification is set to `true` then the delete operation will be cancelled and entity won't be deleted.
7883

79-
Raised when the repository `Delete` method is called and **before** the entity is deleted. The notification contains an `Entity` property providing access to a copy of the entity about to be deleted. If the `Cancel` property of notification is set to `true` then the delete operation will be cancelled and entity won't be deleted.
84+
#### Example
8085

81-
````csharp
82-
// Example
86+
```csharp
8387
public class MyEntityDeletingEventHandler : INotificationHandler<EntityDeletingNotification> {
8488

8589
public void Handle(EntityDeletingNotification notification)
@@ -91,14 +95,15 @@ public class MyEntityDeletingEventHandler : INotificationHandler<EntityDeleting
9195
}
9296

9397
}
94-
````
98+
```
99+
100+
### Using the `EntityDeletedNotification()`
95101

96-
### **EntityDeletedNotification**
102+
Triggers when the repository `Delete` method is called and **after** the entity has been deleted. The notification contains an `Entity` property providing access to a copy of the entity that´s deleted.
97103

98-
Raised when the repository `Delete` method is called and **after** the entity has been deleted. The notification contains an `Entity` property providing access to a copy of the entity that´s deleted.
104+
#### Example
99105

100106
```csharp
101-
// Example
102107
public class MyEntityDeletedEventHandler : INotificationHandler<EntityDeletedNotification> {
103108

104109
public void Handle(EntityDeletedNotification notification)
@@ -112,12 +117,13 @@ public class MyEntityDeletedEventHandler : INotificationHandler<EntityDeletedNo
112117
}
113118
```
114119

115-
### **SqlQueryBuildingNotification**
120+
### Using the `SqlQueryBuildingNotification()`
116121

117-
Raised when the repository is **preparing** a SQL query. The notification contains the collection alias + type, the NPoco `Sql<ISqlContext>` object, and the where clause/order by clauses. These will be used to generate the SQL query.
122+
Triggers when the repository is **preparing** a SQL query. The notification contains the collection alias + type, the NPoco `Sql<ISqlContext>` object, and the where clause/order by clauses. These will be used to generate the SQL query.
123+
124+
#### Example
118125

119126
```csharp
120-
// Example
121127
public class MySqlQueryBuildingEventHandler : INotificationHandler<SqlQueryBuildingNotification> {
122128

123129
public void Handle(SqlQueryBuildingNotification notification)
@@ -128,12 +134,13 @@ public class MySqlQueryBuildingEventHandler : INotificationHandler<SqlQueryBuil
128134
}
129135
```
130136

131-
### **SqlQueryBuiltNotification**
137+
### Using the `SqlQueryBuiltNotification()`
138+
139+
Triggers when the repository has **repaired** a SQL query. The notification contains the collection alias + type, the NPoco `Sql<ISqlContext>` object and the where clause/order by clauses that was used to generate the SQL query.
132140

133-
Raised when the repository has **repaired** a SQL query. The notification contains the collection alias + type, the NPoco `Sql<ISqlContext>` object and the where clause/order by clauses that was used to generate the SQL query.
141+
#### Example
134142

135143
```csharp
136-
// Example
137144
public class MySqlQueryBuiltEventHandler : INotificationHandler<SqlQueryBuiltNotification> {
138145

139146
public void Handle(SqlQueryBuiltNotification notification)
@@ -144,12 +151,13 @@ public class MySqlQueryBuiltEventHandler : INotificationHandler<SqlQueryBuiltNo
144151
}
145152
```
146153

147-
## Repository events validation
154+
## Repository Events Validation
155+
156+
From version `15.1.0`, complex server-side validation can be added to a collection using the `CancelOperation` method of the notification.
148157

149-
Starting with version `15.1.0`, complex server-side validation can be added to a collection by calling the `CancelOperation` method of the notification.
158+
### Example
150159

151160
```csharp
152-
// Example
153161
public class MyEntitySavingEventHandler : INotificationHandler<EntitySavingNotification> {
154162

155163
public void Handle(EntitySavingNotification notification)

15/umbraco-ui-builder/advanced/repositories.md

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
2-
description: Configuring repositories in Umbraco UI Builder, the backoffice UI builder for Umbraco.
2+
description: Configure repositories in Umbraco UI Builder.
33
---
44

55
# Repositories
66

7-
Repositories are used by Umbraco UI Builder to access the entity data stores. By default, collections will use a generic built-in NPoco repository. However, you can define your own repository implementation should you wish to store your entities via an alternative strategy.
7+
Repositories in Umbraco UI Builder manage entity data storage. By default, collections use a built-in NPoco repository. To use a different storage strategy, define a custom repository implementation.
88

9-
## Defining a repository
9+
## Defining a Repository
1010

11-
To define a repository create a class that inherits from the base class `Repository<TEntity, TId>` and implements all of its abstract methods.
11+
Create a class that inherits from `Repository<TEntity, TId>` and implements all abstract methods.
1212

1313
````csharp
1414
// Example
@@ -58,39 +58,62 @@ public class PersonRepository : Repository<Person, int> {
5858
}
5959
````
6060

61-
**Note:** For all `Impl` methods there are public alternatives without the `Impl` suffix. However, there are separate implementation methods in order to ensure all repositories fire the relevant Umbraco UI Builder events. This is whether triggered via the Umbraco UI Builder's UI or not.
61+
{% hint style="info" %}
62+
`Impl` methods have public alternatives without the suffix. Separate implementation methods ensure repositories trigger Umbraco UI Builder events, whether actions originate from the UI or not.
63+
{% endhint %}
6264

63-
## Changing the repository implementation of a collection
65+
## Changing the Repository Implementation of a Collection
6466

65-
### **SetRepositoryType&lt;TRepositoryType&gt;() : CollectionConfigBuilder&lt;TEntityType&gt;**
67+
### Using the `SetRepositoryType()` Method
6668

67-
Sets the repository type to the given type for the current collection.
69+
Assign a custom repository type to a collection.
70+
71+
#### Method Syntax
72+
73+
```cs
74+
SetRepositoryType<TRepositoryType>() : CollectionConfigBuilder<TEntityType>
75+
```
76+
77+
#### Example
6878

6979
````csharp
70-
// Example
7180
collectionConfig.SetRepositoryType<PersonRepositoryType>();
7281
````
7382

74-
### **SetRepositoryType(Type repositoryType) : CollectionConfigBuilder&lt;TEntityType&gt;**
83+
### Using the `SetRepositoryType(Type repositoryType)` Method
7584

76-
Sets the repository type to the given type for the current collection.
85+
Sets the repository type dynamically to the given type for the current collection.
86+
87+
#### Method Syntax
88+
89+
```cs
90+
SetRepositoryType(Type repositoryType) : CollectionConfigBuilder<TEntityType>
91+
```
92+
93+
#### Example
7794

7895
````csharp
79-
// Example
8096
collectionConfig.SetRepositoryType(typeof(PersonRepositoryType));
8197
````
8298

83-
## Accessing a repository in code
99+
## Accessing a Repository in Code
84100

85101
To help with accessing a repository (default or custom) Umbraco UI Builder has an `IRepositoryFactory` you can inject into your code base. This includes a couple of factory methods to create the repository instances for you.
86102
Repositories should only be created via the repository factory as there are some injected dependencies that can only be resolved by Umbraco UI Builder.
87103

88-
### **IRepositoryFactory.GetRepository&lt;TEntity, TId&gt;() : Repository&lt;TEntity, TId&gt;**
104+
### Using the `GetRepository<TEntity, TId>()` Method
89105

90106
Creates a repository for the given entity type. Umbraco UI Builder will search the configuration for the first section/collection with a configuration for the given entity type. Then it will use that as a repository configuration.
91107

108+
#### Method Syntax
109+
110+
```cs
111+
IRepositoryFactory.GetRepository<TEntity, TId>() : Repository<TEntity, TId>
112+
```
113+
114+
#### Example
115+
92116
````csharp
93-
// Example
94117
public class MyController : Controller
95118
{
96119
private readonly Repository<Person, int> _repo;
@@ -102,12 +125,19 @@ public class MyController : Controller
102125
}
103126
````
104127

105-
### **IRepositoryFactory.GetRepository&lt;TEntity, TId&gt;(string collectionAlias) : Repository&lt;TEntity, TId&gt;**
128+
### Using the `GetRepository<TEntity, TId>(string collectionAlias)` Method
106129

107130
Creates a repository for the given entity type from the collection with the given alias.
108131

132+
#### Method Syntax
133+
134+
```cs
135+
IRepositoryFactory.GetRepository<TEntity, TId>(string collectionAlias) : Repository<TEntity, TId>
136+
```
137+
138+
#### Example
139+
109140
````csharp
110-
// Example
111141
public class MyController : Controller
112142
{
113143
private readonly Repository<Person, int> _repo;

0 commit comments

Comments
 (0)