Skip to content

Commit

Permalink
Add example of IXperienceDataContext to README
Browse files Browse the repository at this point in the history
Added a new section titled "Using IXperienceDataContext Example" to the README.md file. This section includes a `ContentService` class demonstrating how to use the `IXperienceDataContext` interface. The `ContentService` class features two methods, `GetContentItemAsync` and `GetPageContentAsync`, which retrieve content items and page content asynchronously using the fluent API provided by `IContentItemContext` and `IPageContentContext`.
  • Loading branch information
bluemodus-brandon authored and brandonhenricks committed Aug 1, 2024
1 parent fc125c2 commit c1eaa45
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,38 @@ public class GenericPageController: Controller
```
This example demonstrates how to asynchronously retrieve the first page content item that matches a given ID, using the fluent API provided by XperienceCommunity.DataContext.

### Using IXperienceDataContext Example:
To demonstrate how to use the IXperienceDataContext interface, consider the following example:


```csharp

public class ContentService
{
private readonly IXperienceDataContext _dataContext;

public ContentService(IXperienceDataContext dataContext)
{
_dataContext = dataContext;
}

public async Task<GenericContent> GetContentItemAsync(Guid contentItemGUID)
{
var contentItemContext = _dataContext.ForContentType<GenericContent>();
return await contentItemContext.FirstOrDefaultAsync(x => x.SystemFields.ContentItemGUID == contentItemGUID);
}

public async Task<GenericPage> GetPageContentAsync(Guid pageGUID)
{
var pageContentContext = _dataContext.ForPageContentType<GenericPage>();
return await pageContentContext.FirstOrDefaultAsync(x => x.SystemFields.PageGUID == pageGUID);
}
}

```
In this example, the ContentService class uses the IXperienceDataContext interface to get contexts for content items and page content. This setup allows you to leverage the fluent API provided by IContentItemContext and IPageContentContext to interact with content items and page content in a type-safe manner.


## Built With

* [Xperience By Kentico](https://www.kentico.com) - Kentico Xperience
Expand Down

0 comments on commit c1eaa45

Please sign in to comment.