{"id":15035644,"url":"https://github.com/brandonhenricks/xperience-community-data-context","last_synced_at":"2025-04-12T04:44:22.582Z","repository":{"id":246419898,"uuid":"821055081","full_name":"brandonhenricks/xperience-community-data-context","owner":"brandonhenricks","description":"XperienceCommunity.DataContext, a .NET 8 library that simplifies Kentico Xperience development with a fluent API for efficient query building and seamless integration.","archived":false,"fork":false,"pushed_at":"2024-12-28T16:48:04.000Z","size":162,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T00:13:08.898Z","etag":null,"topics":["csharp-code","dotnet-core","kentico","xperience","xperience-by-kentico"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brandonhenricks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-27T18:06:58.000Z","updated_at":"2024-12-20T23:19:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"a1134dfa-5e1d-4954-9383-fa96243328ea","html_url":"https://github.com/brandonhenricks/xperience-community-data-context","commit_stats":null,"previous_names":["brandonhenricks/xperience-community-data-context"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonhenricks%2Fxperience-community-data-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonhenricks%2Fxperience-community-data-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonhenricks%2Fxperience-community-data-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonhenricks%2Fxperience-community-data-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brandonhenricks","download_url":"https://codeload.github.com/brandonhenricks/xperience-community-data-context/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248519471,"owners_count":21117757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp-code","dotnet-core","kentico","xperience","xperience-by-kentico"],"created_at":"2024-09-24T20:29:07.055Z","updated_at":"2025-04-12T04:44:22.556Z","avatar_url":"https://github.com/brandonhenricks.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XperienceCommunity.DataContext\n\nEnhance your Kentico Xperience development with a fluent API for intuitive and efficient query building. This project abstracts the built-in ContentItemQueryBuilder, leveraging .NET 8 and integrated with Xperience By Kentico, to improve your local development and testing workflow.\n\n## Features\n\n- Fluent API for query building with expressions.\n- Built in caching.\n- Built on .NET6/.NET 8, ensuring modern development practices.\n- Seamless integration with Xperience By Kentico.\n\n## Quick Start\n\n1. **Prerequisites:** Ensure you have .NET 6/.NET 8 and Kentico Xperience installed.\n2. **Installation:** Install this project through Nuget.\n\n## Prerequisites\n\nBefore you begin, ensure you have met the following requirements:\n\n- **.NET:** Make sure you have a .NET 6, or .NET 8 installed on your development machine. You can download it from [here](https://dotnet.microsoft.com/download/dotnet/8.0).\n- **Xperience By Kentico Project:** You need an existing Xperience By Kentico project. If you're new to Xperience By Kentico, start [here](https://docs.xperience.io/).\n\n## Installation\n\nTo integrate XperienceCommunity.DataContext into your Kentico Xperience project, follow these steps:\n\n1. **NuGet Package**: Install the NuGet package via the Package Manager Console.\n\n   ```shell\n   Install-Package XperienceCommunity.DataContext\n   ```\n\n2. **Configure Services:**\n   - In your `Startup.cs` or wherever you configure services, add the following line to register XperienceCommunity.DataContext services with dependency injection:\n\n```csharp\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.AddXperienceDataContext();\n}\n```\n\n## Injecting the `IContentItemContext` into a Class\n\nTo leverage the `IContentItemContext` in your classes, you need to inject it via dependency injection. The `IContentItemContext` requires a class that implements the `IContentItemFieldSource` interface. For instance, you might have a `GenericContent` class designed for the Content Hub.\n\n### Querying Content Items Example:\n\nAssuming you have a `GenericContent` class that implements `IContentItemFieldSource`, you can inject the `IContentItemContext\u003cGenericContent\u003e` into your classes as follows:\n\n```csharp\npublic class MyService\n{\n    private readonly IContentItemContext\u003cGenericContent\u003e _contentItemContext;\n\n    public MyService(IContentItemContext\u003cGenericContent\u003e contentItemContext)\n    {\n        _contentItemContext = contentItemContext;\n    }\n\n    // Example method using the _contentItemContext\n    public async Task\u003cGenericContent\u003e GetContentItemAsync(Guid contentItemGUID)\n    {\n        return await _contentItemContext\n            .FirstOrDefaultAsync(x =\u003e x.SystemFields.ContentItemGUID == contentItemGUID);\n    }\n}\n```\n\nThis setup allows you to utilize the fluent API provided by `IContentItemContext` to interact with content items in a type-safe manner, enhancing the development experience with Kentico Xperience.\n## Example Usage\n\nHere's a quick example to show how you can use XperienceCommunity.DataContext in your project:\n\n```csharp\nvar result = await _context\n    .WithLinkedItems(1)\n    .FirstOrDefaultAsync(x =\u003e x.SystemFields.ContentItemGUID == selected.Identifier, HttpContext.RequestAborted);\n```\n\nThis example demonstrates how to asynchronously retrieve the first content item that matches a given GUID, with a single level of linked items included, using the fluent API provided by XperienceCommunity.DataContext.\n\n### Querying Page Content Example:\n\nAssuming you have a `GenericPage` class that implements `IWebPageFieldsSource`, you can inject the `IPageContentContext\u003cGenericPage\u003e` into your classes as follows:\n\n```csharp\npublic class GenericPageController: Controller\n{\n    private readonly IPageContentContext\u003cGenericPage\u003e _pageContext;\n    private readonly IWebPageDataContextRetriever _webPageDataContextRetriever;\n\n    public GenericPageController(IPageContentContext\u003cGenericPage\u003e pageContext\n            IWebPageDataContextRetriever webPageDataContextRetriever)\n    {\n        _pageContext = pageContext;\n        _webPageDataContextRetriever = webPageDataContextRetriever;\n    }\n\n    // Example method using the _pageContext\n    public async Task\u003cIActionResult\u003e IndexAsync()\n    {           \n         var page = _webPageDataContextRetriever.Retrieve().WebPage;\n\n        if (page == null)\n        {\n            return NotFound();\n        }\n\n        var content = await _pageContext\n            .FirstOrDefaultAsync(x =\u003e x.SystemFields.WebPageItemID == page.WebPageItemID, HttpContext.RequestAborted);\n\n        if (content == null)\n        {\n            return NotFound();\n        }\n\n        return View(conent);\n    }\n}\n```\nThis example demonstrates how to asynchronously retrieve the first page content item that matches a given ID, using the fluent API provided by XperienceCommunity.DataContext.\n\n### Using IXperienceDataContext Example:\nTo demonstrate how to use the IXperienceDataContext interface, consider the following example:\n\n\n```csharp\n\npublic class ContentService\n{\n    private readonly IXperienceDataContext _dataContext;\n\n    public ContentService(IXperienceDataContext dataContext)\n    {\n        _dataContext = dataContext;\n    }\n\n    public async Task\u003cGenericContent\u003e GetContentItemAsync(Guid contentItemGUID)\n    {\n        var contentItemContext = _dataContext.ForContentType\u003cGenericContent\u003e();\n        return await contentItemContext.FirstOrDefaultAsync(x =\u003e x.SystemFields.ContentItemGUID == contentItemGUID);\n    }\n\n    public async Task\u003cGenericPage\u003e GetPageContentAsync(Guid pageGUID)\n    {\n        var pageContentContext = _dataContext.ForPageContentType\u003cGenericPage\u003e();\n        return await pageContentContext.FirstOrDefaultAsync(x =\u003e x.SystemFields.PageGUID == pageGUID);\n    }\n}\n\n```\nIn 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.\n\n\n## Built With\n\n* [Xperience By Kentico](https://www.kentico.com) - Kentico Xperience\n* [NuGet](https://nuget.org/) - Dependency Management\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/your/project/tags). \n\n## Authors\n\n* **Brandon Henricks** - *Initial work* - [Brandon Henricks](https://github.com/brandonhenricks)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n\n## Acknowledgments\n\n* [Mike Wills](https://github.com/heywills)\n* David Rector\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonhenricks%2Fxperience-community-data-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrandonhenricks%2Fxperience-community-data-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonhenricks%2Fxperience-community-data-context/lists"}