You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 17/umbraco-cms/customizing/foundation/repositories/README.md
+41-16Lines changed: 41 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# Repositories
2
2
Repositories provide a structured way to manage data operations in the Backoffice. They abstract the data access layer, allowing for easier reuse and scalability.
3
3
4
-
Repositories create separation between domain logic and data access. By providing a known interface for data requests, we can reuse UI components across different domains. For example, we have a generic UX flow for deleting an entity. By supplying this flow with a repository that has a known interface for deletion, we can use the same UX flow to delete any entity.
4
+
Repositories create separation between domain logic and data access. By providing a known interface for data requests, we can reuse UI components across different domains. For example, we have a generic UX flow for deleting an entity. By supplying this flow with a repository that has a known interface for deletion, we can use the same UX flow to delete any entity. The same applies to Trees, Collections, Workspaces, and more.
5
5
6
6
Additionally repositories can utilize different data sources depending on the application's state. These sources may include:
7
7
@@ -17,40 +17,68 @@ This abstraction ensures that consumers don’t need to worry about how to acces
17
17
18
18
### Data flow with a repository <ahref="#data-flow-with-a-repository"id="data-flow-with-a-repository"></a>
19
19
20
-
A repository must be instantiated where it is used. It should take an [UmbController](../../umbraco-controller/README.md) as part of the constructor. This ensures that any contexts consumed in the repository, like notifications or modals, are rendered in the correct context.
20
+
A repository must be instantiated where it is used. It should take an [UmbController](../../umbraco-controller/README.md) as part of the constructor. This ensures that any contexts consumed in the repositoryare scoped correctly.
21
21
22
22
A repository can be initialized directly from an element, but will often be instantiated in a [context](../../context-api/README.md), like the Workspace Context.
23
23
24
+
The data flow when using a repository can be illustrated as follows:
25
+
24
26
```text
25
-
Element → (Context) → Repository → Data Source(s)
27
+
(Data Source) -> Repository -> (Controller/Context) -> Element
26
28
```
27
29
28
30
### Using an existing Repository <ahref="#using-a-repository"id="using-a-repository"></a>
29
31
30
32
Often, you will find that data is already available and observable in a [context](./contexts/README.md). In that case, subscribing to the context [state](./states.md) will be the right approach to take. This way, you will receive all runtime updates that occur to the data throughout the session.
31
33
32
-
When a context with the appropriate data state is not available, reaching for a repository will ensure access to the needed information no matter the current application state.
34
+
When a context with the appropriate data state is not available, reaching for a repository will ensure access to the needed data no matter the current application state.
35
+
36
+
In the example below, we instantiate the `UmbDocumentItemRepository` directly in a custom element to request Document data by its unique key.
Alternatively, you can instantiate the repository in a [controller](..) or [context](../../context-api/README.md), store it in a [state](../states.md), and then consume that context in your element. This is often the preferred approach as it allows for better separation of concerns and reusability across different components.
// The items state can now be observed by any element initializing this controller
77
+
}
78
+
}
52
79
```
53
80
81
+
54
82
### Register a custom Repository <ahref="#register-a-custom-repository"id="register-a-custom-repository"></a>
55
83
56
84
By registering your repository in the [Extension Registry](../../extension-registry/README.md) you make it available to use in different extension kinds that requires a repository alias.
@@ -65,21 +93,18 @@ See the example below of how to register a custom repository:
0 commit comments