diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..588faf3
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,3 @@
+[*.{yml,yaml}]
+indent_style = space
+indent_size = 2
\ No newline at end of file
diff --git a/.github/ISSUE_TEMPLATE/Bug Report.yml b/.github/ISSUE_TEMPLATE/Bug Report.yml
new file mode 100644
index 0000000..374d363
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/Bug Report.yml
@@ -0,0 +1,42 @@
+name: Bug Report
+description: File a bug report.
+labels: ["bug"]
+body:
+ - type: textarea
+ id: what-happened
+ attributes:
+ label: What happened?
+ value: |
+ Description
+
+
+ Reproduction Steps
+ 1. Open
+ 2. Execute
+
+ Actual Behavior
+
+ Expected Behavior
+ validations:
+ required: true
+
+ - type: textarea
+ id: logs
+ attributes:
+ label: Relevant log output
+ description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
+ render: shell
+
+ - type: checkboxes
+ id: terms
+ attributes:
+ label: Code of Conduct
+ description: By submitting this issue, you agree to follow our [Code of Conduct](CODE_OF_CONDUCT.md).
+ options:
+ - label: I agree to follow this project's Code of Conduct
+ required: true
+
+ - type: markdown
+ attributes:
+ value: |
+ Thanks for taking the time to fill out this bug report!
\ No newline at end of file
diff --git a/.github/ISSUE_TEMPLATE/Feature Request.yml b/.github/ISSUE_TEMPLATE/Feature Request.yml
new file mode 100644
index 0000000..ce003e5
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/Feature Request.yml
@@ -0,0 +1,24 @@
+name: Feature Request
+description: Request a new feature.
+labels: ["enhancement"]
+body:
+ - type: textarea
+ id: feature
+ attributes:
+ label: What would you add to the SDK?
+ validations:
+ required: true
+
+ - type: checkboxes
+ id: terms
+ attributes:
+ label: Code of Conduct
+ description: By submitting this feature, you agree to follow our [Code of Conduct](CODE_OF_CONDUCT.md).
+ options:
+ - label: I agree to follow this project's Code of Conduct
+ required: true
+
+ - type: markdown
+ attributes:
+ value: |
+ Thanks for taking the time to fill out this feature request!
\ No newline at end of file
diff --git a/.github/ISSUE_TEMPLATE/Question.yml b/.github/ISSUE_TEMPLATE/Question.yml
new file mode 100644
index 0000000..491deba
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/Question.yml
@@ -0,0 +1,18 @@
+name: Question
+description: Ask any question about the project.
+body:
+ - type: textarea
+ id: question
+ attributes:
+ label: What is your question?
+ validations:
+ required: true
+
+ - type: checkboxes
+ id: terms
+ attributes:
+ label: Code of Conduct
+ description: By submitting this question, you agree to follow our [Code of Conduct](CODE_OF_CONDUCT.md).
+ options:
+ - label: I agree to follow this project's Code of Conduct
+ required: true
\ No newline at end of file
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
new file mode 100644
index 0000000..ef5fa01
--- /dev/null
+++ b/.github/pull_request_template.md
@@ -0,0 +1,19 @@
+
+
+
+## Description / Motivation
+
+
+
+
+
+## Testing
+
+- [ ] The Unit & Intergration tests are passing.
+- [ ] I have added the necesary tests to cover my changes.
+
+## Terms
+
+
+
+- [ ] I agree to follow this project's [Code of Conduct](CODE_OF_CONDUCT.md).
diff --git a/.github/workflows/Version.ps1 b/.github/workflows/Version.ps1
new file mode 100644
index 0000000..b3275bb
--- /dev/null
+++ b/.github/workflows/Version.ps1
@@ -0,0 +1,86 @@
+[CmdletBinding()]
+Param (
+ [Parameter(HelpMessage = "Path to the file to append the version elements in.")]
+ [string]$Path,
+ [Parameter(HelpMessage = "Previous version to calculate the next version on. Must be like '1.0.0'.")]
+ [string]$PreviousVersion,
+ [Parameter(HelpMessage = "Commit Message")]
+ [string]$Message
+)
+
+function Get-Version
+{
+ param (
+ [string]$PreviousVersion,
+ [string]$Message
+ )
+
+ $versionNumbers = $PreviousVersion -split "\."
+ $major = [int]$versionNumbers[0]
+ $minor = [int]$versionNumbers[1]
+ $patch = [int]$versionNumbers[2]
+
+ if ($Env:GITHUB_REF -like "refs/pull/*/feat/*" -or $Message -like "FEAT: *") {
+ $minor++
+ $patch = 0
+ } elseif ($Env:GITHUB_REF -like "refs/pull/*/new/*" -or $Message -like "NEW: *") {
+ $major++
+ $minor = 0
+ $patch = 0
+ } else {
+ $patch++
+ }
+
+ return "$major.$minor.$patch"
+}
+
+function Get-VersionSuffix
+{
+ if ($Env:GITHUB_REF -like "refs/pull/*") {
+ $prId = $Env:GITHUB_REF -replace "refs/pull/(\d+)/.*", '$1'
+ $versionSuffix = "pr.$prId.$Env:GITHUB_RUN_NUMBER"
+ } else {
+ $versionSuffix = ""
+ }
+
+ return $versionSuffix
+}
+
+function Set-Version
+{
+ param (
+ [string]$Path,
+ [string]$Version,
+ [string]$Suffix
+ )
+
+ $xml = [xml](Get-Content -Path $Path)
+ $properties = $xml.Project.PropertyGroup
+
+ $assemblyVersionElement = $xml.CreateElement("AssemblyVersion")
+ $assemblyVersionElement.InnerText = "$Version.$Env:GITHUB_RUN_NUMBER"
+
+ $versionElement = $xml.CreateElement("VersionPrefix")
+ $versionElement.InnerText = $Version
+
+ $fileVersionElement = $xml.CreateElement("FileVersion")
+ $fileVersionElement.InnerText = "$Version.$Env:GITHUB_SHA"
+
+ if (![string]::IsNullOrEmpty($Suffix)) {
+ $suffixElement = $xml.CreateElement("VersionSuffix")
+ $suffixElement.InnerText = $Suffix
+ $properties.AppendChild($suffixElement)
+ }
+
+ $properties.AppendChild($assemblyVersionElement)
+ $properties.AppendChild($versionElement)
+ $properties.AppendChild($fileVersionElement)
+
+ $xml.Save($Path)
+}
+
+$newVersion = Get-Version $PreviousVersion $Message
+$suffix = Get-VersionSuffix
+Set-Version $Path $newVersion $suffix | Out-Null
+
+return "newVersion=$newVersion"
\ No newline at end of file
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..c8dfbb0
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,114 @@
+name: Build
+
+on:
+ workflow_call:
+ inputs:
+ buildConfiguration:
+ type: string
+ required: true
+ description: 'The build configuration to use'
+ default: 'Release'
+ outputs:
+ newVersion:
+ description: 'The new version number'
+ value: ${{ jobs.build.outputs.newVersion }}
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ outputs:
+ newVersion: ${{ steps.version.outputs.newVersion }}
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Get Version Info
+ uses: actions/github-script@v7
+ id: get-version-info
+ with:
+ script: |
+ async function getLatestRelease() {
+ try {
+ const response = await github.rest.repos.getLatestRelease({
+ owner: context.repo.owner,
+ repo: context.repo.repo
+ });
+ core.info('Previous Release Version = ' + response.data.tag_name);
+ core.setOutput('previousVersion', response.data.tag_name);
+ } catch (error) {
+ if (error.status === 404) {
+ core.info('No releases found for this repository.');
+ core.setOutput('previousVersion', '0.0.0');
+ } else {
+ console.error('An error occurred while fetching the latest release: ', error);
+ throw error;
+ }
+ }
+ }
+
+ async function getCommitMessage() {
+ try {
+ const response = await github.rest.repos.getCommit({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ ref: context.sha
+ });
+ core.info('Commit Message = ' + response.data.commit.message);
+ core.setOutput('commitMessage', response.data.commit.message);
+ } catch (error) {
+ console.error('An error occurred while fetching the commit message: ', error);
+ throw error;
+ }
+ }
+
+ await getLatestRelease();
+ await getCommitMessage();
+
+ - name: Version
+ id: version
+ shell: pwsh
+ run: |
+ $message = @"
+ ${{ steps.get-version-info.outputs.commitMessage }}
+ "@
+ ./.github/workflows/Version.ps1 -Path "./src/Directory.Build.props" -PreviousVersion ${{ steps.get-version-info.outputs.previousVersion }} -Message $message >> $Env:GITHUB_OUTPUT
+
+ - name: Setup .NET
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: 8.0.x
+
+ - name: Restore dependencies
+ run: dotnet restore
+
+ - name: Build
+ run: dotnet build -c ${{ inputs.buildConfiguration }} --no-restore
+
+ - name: Test
+ run: dotnet test -c ${{ inputs.buildConfiguration }} --no-build --verbosity normal --logger trx --collect:"XPlat Code Coverage" --results-directory TestResults
+
+ - name: Upload dotnet test results
+ uses: actions/upload-artifact@v4
+ with:
+ name: test-results
+ path: TestResults
+ if: ${{ always() }}
+
+ - name: Run Benchmarks
+ working-directory: ./tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks
+ run: dotnet run -c Release
+
+ - name: Upload benchmark results
+ uses: actions/upload-artifact@v4
+ with:
+ name: perf-results
+ path: ./tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/BenchmarkDotNet.Artifacts
+
+ - name: Package
+ run: dotnet pack -c ${{ inputs.buildConfiguration }} --no-build --output nupkgs
+
+ - name: Upload packages
+ uses: actions/upload-artifact@v4
+ with:
+ name: packages
+ path: nupkgs
\ No newline at end of file
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100644
index 0000000..c6e7a88
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -0,0 +1,85 @@
+name: CICD
+
+on:
+ push:
+ branches: [ "main" ]
+
+concurrency:
+ group: "cicd"
+ cancel-in-progress: false
+
+jobs:
+ build:
+ uses: ./.github/workflows/build.yml
+ with:
+ buildConfiguration: Release
+ release:
+ needs: build
+ runs-on: ubuntu-latest
+ steps:
+ - name: Create Release
+ id: create-release
+ uses: actions/github-script@v7
+ with:
+ script: |
+ const newVersion = '${{ needs.build.outputs.newVersion }}';
+ const response = await github.rest.repos.createRelease({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ tag_name: newVersion,
+ target_commitish: context.sha,
+ name: newVersion,
+ generate_release_notes: true
+ });
+ core.setOutput('upload_url', response.data.upload_url);
+
+ - name: Download Artifact Packages
+ uses: actions/download-artifact@v4
+ with:
+ name: packages
+ path: ./artifacts
+
+ - name: Attach Release Assets
+ uses: actions/github-script@v7
+ with:
+ script: |
+ const uploadUrl = '${{ steps.create-release.outputs.upload_url }}';
+ const fs = require('fs');
+ const path = require('path');
+ const packages = fs.readdirSync('./artifacts').filter(file => file.endsWith('.nupkg'));
+ for (const file of packages) {
+ const filePath = path.join('./artifacts', file);
+ const name = path.basename(filePath);
+ const response = await github.rest.repos.uploadReleaseAsset({
+ url: uploadUrl,
+ headers: {
+ 'content-type': 'application/zip',
+ 'content-length': fs.statSync(filePath).size
+ },
+ name: name,
+ data: fs.readFileSync(filePath)
+ });
+ core.info('Uploaded ' + name);
+ }
+ publish-docs:
+ environment:
+ name: github-pages
+ url: ${{ steps.deployment.outputs.page_url }}
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ - name: Dotnet Setup
+ uses: actions/setup-dotnet@v3
+ with:
+ dotnet-version: 8.x
+ - run: dotnet tool update -g docfx
+ - run: docfx ./docfx/docfx.json
+ - name: Upload artifact
+ uses: actions/upload-pages-artifact@v3
+ with:
+ # Upload entire repository
+ path: './docfx/_site'
+ - name: Deploy to GitHub Pages
+ id: deployment
+ uses: actions/deploy-pages@v4
\ No newline at end of file
diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml
new file mode 100644
index 0000000..442de12
--- /dev/null
+++ b/.github/workflows/pullrequest.yml
@@ -0,0 +1,11 @@
+name: PR
+
+on:
+ pull_request:
+ branches: [ "main" ]
+
+jobs:
+ build:
+ uses: ./.github/workflows/build.yml
+ with:
+ buildConfiguration: Release
\ No newline at end of file
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 0000000..20bcc4f
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,133 @@
+
+# Contributor Covenant Code of Conduct
+
+## Our Pledge
+
+We as members, contributors, and leaders pledge to make participation in our
+community a harassment-free experience for everyone, regardless of age, body
+size, visible or invisible disability, ethnicity, sex characteristics, gender
+identity and expression, level of experience, education, socio-economic status,
+nationality, personal appearance, race, caste, color, religion, or sexual
+identity and orientation.
+
+We pledge to act and interact in ways that contribute to an open, welcoming,
+diverse, inclusive, and healthy community.
+
+## Our Standards
+
+Examples of behavior that contributes to a positive environment for our
+community include:
+
+* Demonstrating empathy and kindness toward other people
+* Being respectful of differing opinions, viewpoints, and experiences
+* Giving and gracefully accepting constructive feedback
+* Accepting responsibility and apologizing to those affected by our mistakes,
+ and learning from the experience
+* Focusing on what is best not just for us as individuals, but for the overall
+ community
+
+Examples of unacceptable behavior include:
+
+* The use of sexualized language or imagery, and sexual attention or advances of
+ any kind
+* Trolling, insulting or derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or email address,
+ without their explicit permission
+* Other conduct which could reasonably be considered inappropriate in a
+ professional setting
+
+## Enforcement Responsibilities
+
+Community leaders are responsible for clarifying and enforcing our standards of
+acceptable behavior and will take appropriate and fair corrective action in
+response to any behavior that they deem inappropriate, threatening, offensive,
+or harmful.
+
+Community leaders have the right and responsibility to remove, edit, or reject
+comments, commits, code, wiki edits, issues, and other contributions that are
+not aligned to this Code of Conduct, and will communicate reasons for moderation
+decisions when appropriate.
+
+## Scope
+
+This Code of Conduct applies within all community spaces, and also applies when
+an individual is officially representing the community in public spaces.
+Examples of representing our community include using an official email address,
+posting via an official social media account, or acting as an appointed
+representative at an online or offline event.
+
+## Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be
+reported to the community leaders responsible for enforcement at
+[INSERT CONTACT METHOD].
+All complaints will be reviewed and investigated promptly and fairly.
+
+All community leaders are obligated to respect the privacy and security of the
+reporter of any incident.
+
+## Enforcement Guidelines
+
+Community leaders will follow these Community Impact Guidelines in determining
+the consequences for any action they deem in violation of this Code of Conduct:
+
+### 1. Correction
+
+**Community Impact**: Use of inappropriate language or other behavior deemed
+unprofessional or unwelcome in the community.
+
+**Consequence**: A private, written warning from community leaders, providing
+clarity around the nature of the violation and an explanation of why the
+behavior was inappropriate. A public apology may be requested.
+
+### 2. Warning
+
+**Community Impact**: A violation through a single incident or series of
+actions.
+
+**Consequence**: A warning with consequences for continued behavior. No
+interaction with the people involved, including unsolicited interaction with
+those enforcing the Code of Conduct, for a specified period of time. This
+includes avoiding interactions in community spaces as well as external channels
+like social media. Violating these terms may lead to a temporary or permanent
+ban.
+
+### 3. Temporary Ban
+
+**Community Impact**: A serious violation of community standards, including
+sustained inappropriate behavior.
+
+**Consequence**: A temporary ban from any sort of interaction or public
+communication with the community for a specified period of time. No public or
+private interaction with the people involved, including unsolicited interaction
+with those enforcing the Code of Conduct, is allowed during this period.
+Violating these terms may lead to a permanent ban.
+
+### 4. Permanent Ban
+
+**Community Impact**: Demonstrating a pattern of violation of community
+standards, including sustained inappropriate behavior, harassment of an
+individual, or aggression toward or disparagement of classes of individuals.
+
+**Consequence**: A permanent ban from any sort of public interaction within the
+community.
+
+## Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage],
+version 2.1, available at
+[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
+
+Community Impact Guidelines were inspired by
+[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
+
+For answers to common questions about this code of conduct, see the FAQ at
+[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
+[https://www.contributor-covenant.org/translations][translations].
+
+[homepage]: https://www.contributor-covenant.org
+[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
+[Mozilla CoC]: https://github.com/mozilla/diversity
+[FAQ]: https://www.contributor-covenant.org/faq
+[translations]: https://www.contributor-covenant.org/translations
diff --git a/Directory.Packages.props b/Directory.Packages.props
new file mode 100644
index 0000000..ba368c8
--- /dev/null
+++ b/Directory.Packages.props
@@ -0,0 +1,42 @@
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
\ No newline at end of file
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..7a4a3ea
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..45fa4cb
--- /dev/null
+++ b/README.md
@@ -0,0 +1,40 @@
+# Sitecore ASP.NET Core SDK
+
+This repository contains source code for all Sitecore ASP.NET Core SDK packages and templates to help you get started using the Sitecore ASP.NET Core SDK.
+
+## Getting started
+
+## Documentation and Community Resources
+
+- [Official Documentation](https://doc.sitecore.com/xp/en/developers/hd/latest/sitecore-headless-development/sitecore-asp-net-rendering-sdk.html)
+- [StackExchange](https://sitecore.stackexchange.com/)
+ - Be sure to tag your question with the `aspnetcoresdk` tag.
+- [Community Slack](https://sitecorechat.slack.com/messages/general)
+ - If you're not already a member of the Sitecore Community Slack, you can find more information here: https://siteco.re/sitecoreslack
+- [Sitecore Community Forum](https://community.sitecore.com/community)
+
+## Contributions
+
+We are very grateful to the community for contributing bug fixes and improvements. We welcome all efforts to evolve and improve the Sitecore ASP.NET Core SDK; read below to learn how to participate in those efforts.
+
+### [Code of Conduct](CODE_OF_CONDUCT.md)
+
+Sitecore has adopted a Code of Conduct that we expect project participants to adhere to. Please read [the full text](CODE_OF_CONDUCT.md) so that you can understand what actions will and will not be tolerated.
+
+### [Contributing Guide](CONTRIBUTING.md)
+
+Read our [contributing guide](CONTRIBUTING.md) to learn about our development process, how to propose bug fixes and improvements, and how to build and test your changes.
+
+### License
+
+The Sitecore ASP.NET Core SDK is using the [Apache 2.0 license](LICENSE.MD).
+
+## Support
+
+### Issues / Bugs / Feature Requests
+
+Open an issue via [GitHub](https://github.com/Sitecore/ASP.NET-Core-SDK/issues)
+
+Please use one of the provided templates when opening an issue, it will greatly increase your chances of a prompt response.
+
+Also, please try to refrain from asking "How to...?" questions via GitHub issues. If you have questions about how to use the SDK or implement something specific with the SDK, you'll likely find more success referring to the documentation, posting to Sitecore StackExchange, or chatting on Slack.
diff --git a/Sitecore.AspNetCore.SDK.sln b/Sitecore.AspNetCore.SDK.sln
new file mode 100644
index 0000000..5d2e34b
--- /dev/null
+++ b/Sitecore.AspNetCore.SDK.sln
@@ -0,0 +1,223 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.9.34701.34
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{03E05F99-1A3F-409C-8C8B-7DFE4265D56D}"
+ ProjectSection(SolutionItems) = preProject
+ .editorconfig = .editorconfig
+ Directory.Packages.props = Directory.Packages.props
+ nuget.config = nuget.config
+ EndProjectSection
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0BE1019D-F812-4B03-9A6F-E3073A1CF0C9}"
+ ProjectSection(SolutionItems) = preProject
+ src\Directory.Build.props = src\Directory.Build.props
+ src\GlobalSuppressions.cs = src\GlobalSuppressions.cs
+ EndProjectSection
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Layout Service Client", "Layout Service Client", "{43F06962-0100-488C-8EF5-4735E85A545C}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.LayoutService.Client", "src\Sitecore.AspNetCore.SDK.LayoutService.Client\Sitecore.AspNetCore.SDK.LayoutService.Client.csproj", "{B4833145-90B3-410E-9240-510B32E5FDA4}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Rendering Engine", "Rendering Engine", "{75482B5D-21E2-4DBE-BE78-657ECF0D409F}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.GraphQL", "src\Sitecore.AspNetCore.SDK.GraphQL\Sitecore.AspNetCore.SDK.GraphQL.csproj", "{9A69EEE4-F7D2-4693-B557-E4D338F241C4}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.RenderingEngine", "src\Sitecore.AspNetCore.SDK.RenderingEngine\Sitecore.AspNetCore.SDK.RenderingEngine.csproj", "{EA632DA8-39FA-4181-8475-7D01FB5EA480}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.ExperienceEditor", "src\Sitecore.AspNetCore.SDK.ExperienceEditor\Sitecore.AspNetCore.SDK.ExperienceEditor.csproj", "{64B00F65-B625-47E3-BD4C-779556DEA018}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.SearchOptimization", "src\Sitecore.AspNetCore.SDK.SearchOptimization\Sitecore.AspNetCore.SDK.SearchOptimization.csproj", "{C0A69C38-9A77-4875-B3A9-9F170365D772}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.Tracking", "src\Sitecore.AspNetCore.SDK.Tracking\Sitecore.AspNetCore.SDK.Tracking.csproj", "{F19C565A-047C-4C91-AE2C-43687C9193FE}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.Tracking.VisitorIdentification", "src\Sitecore.AspNetCore.SDK.Tracking.VisitorIdentification\Sitecore.AspNetCore.SDK.Tracking.VisitorIdentification.csproj", "{109EAE14-6424-42F8-9877-0AB958A70E02}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{29DBF993-B6A4-4FA6-9CAA-730B319C164E}"
+ ProjectSection(SolutionItems) = preProject
+ tests\Directory.Build.props = tests\Directory.Build.props
+ tests\Tests.GlobalSuppressions.cs = tests\Tests.GlobalSuppressions.cs
+ EndProjectSection
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Layout Service Client", "Layout Service Client", "{61050ECA-956C-4BE1-8187-781603DC35C1}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.AutoFixture", "tests\Sitecore.AspNetCore.SDK.AutoFixture\Sitecore.AspNetCore.SDK.AutoFixture.csproj", "{9B95B4AD-E26A-40A1-A159-C75FB53C0821}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "data", "data", "{B47DBA4E-A9DA-4830-8EED-CFA0B798740C}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "json", "json", "{C309DD88-CE7C-4E8B-A068-0D4BDF824A02}"
+ ProjectSection(SolutionItems) = preProject
+ tests\data\json\devices.json = tests\data\json\devices.json
+ tests\data\json\edit-in-horizon-mode.json = tests\data\json\edit-in-horizon-mode.json
+ tests\data\json\edit.json = tests\data\json\edit.json
+ tests\data\json\layoutResponse.json = tests\data\json\layoutResponse.json
+ tests\data\json\mixedComponentsEditChromes.json = tests\data\json\mixedComponentsEditChromes.json
+ tests\data\json\onlyComponents.json = tests\data\json\onlyComponents.json
+ tests\data\json\onlyEditChromes.json = tests\data\json\onlyEditChromes.json
+ EndProjectSection
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.LayoutService.Client.Tests", "tests\Sitecore.AspNetCore.SDK.LayoutService.Client.Tests\Sitecore.AspNetCore.SDK.LayoutService.Client.Tests.csproj", "{161F477E-4963-45B2-A0AD-CB7DB9A445FA}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.TestData", "tests\data\Sitecore.AspNetCore.SDK.TestData\Sitecore.AspNetCore.SDK.TestData.csproj", "{3E62CA06-4823-412D-99B6-231B76C8CB71}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Unit", "Unit", "{B75F7FED-DAA6-41DC-ACBA-2193B9E0A685}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Integration", "Integration", "{D301D535-E35D-49E7-ADD7-F45D4CF9604B}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.LayoutService.Client.Integration.Tests", "tests\Sitecore.AspNetCore.SDK.LayoutService.Client.Integration.Tests\Sitecore.AspNetCore.SDK.LayoutService.Client.Integration.Tests.csproj", "{4FF52EAA-D14E-4BFB-939C-FB79A968E2AC}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Rendering Engine", "Rendering Engine", "{5E0267C1-E1B1-471A-951C-4AC894F870B8}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Performance", "Performance", "{1B31C12C-5D18-4675-8378-FBD9EEEF3793}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks", "tests\Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks\Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks.csproj", "{C01864D0-AE4F-404C-BAF3-626974FC7290}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Unit", "Unit", "{BDE3D3B9-8291-4AE9-B8DA-868CEBCBDC4D}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.RenderingEngine.Tests", "tests\Sitecore.AspNetCore.SDK.RenderingEngine.Tests\Sitecore.AspNetCore.SDK.RenderingEngine.Tests.csproj", "{C47DB8DA-5534-4A74-ACA1-C1AC9D1FAB4A}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Integration", "Integration", "{7C5D334A-FBCF-42E9-8E08-99C6894D9A4D}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests", "tests\Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests\Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.csproj", "{74FA9495-EBAA-4204-9D9A-4BDD025A637A}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.ExperienceEditor.Tests", "tests\Sitecore.AspNetCore.SDK.ExperienceEditor.Tests\Sitecore.AspNetCore.SDK.ExperienceEditor.Tests.csproj", "{68302AAF-A2BA-4B15-8D63-AE03C641D38A}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.GraphQL.Tests", "tests\Sitecore.AspNetCore.SDK.GraphQL.Tests\Sitecore.AspNetCore.SDK.GraphQL.Tests.csproj", "{1229ED65-0C15-468B-A979-C41B52C68D65}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sitecore.AspNetCore.SDK.Tracking.Tests", "tests\Sitecore.AspNetCore.SDK.Tracking.Tests\Sitecore.AspNetCore.SDK.Tracking.Tests.csproj", "{100C07C6-C68D-469F-9F15-139CB48CB7F0}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GitHub", "GitHub", "{5FE82369-DEF2-4136-B74F-6E86DB91050E}"
+ ProjectSection(SolutionItems) = preProject
+ .github\pull_request_template.md = .github\pull_request_template.md
+ EndProjectSection
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{1706E43D-AC19-4FBB-9BFB-18A8B195580A}"
+ ProjectSection(SolutionItems) = preProject
+ .github\workflows\build.yml = .github\workflows\build.yml
+ .github\workflows\main.yml = .github\workflows\main.yml
+ .github\workflows\pullrequest.yml = .github\workflows\pullrequest.yml
+ .github\workflows\Version.ps1 = .github\workflows\Version.ps1
+ EndProjectSection
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ISSUE_TEMPLATE", "ISSUE_TEMPLATE", "{24CCC156-046B-4600-9DB0-FC3269A18747}"
+ ProjectSection(SolutionItems) = preProject
+ .github\ISSUE_TEMPLATE\Bug Report.yml = .github\ISSUE_TEMPLATE\Bug Report.yml
+ .github\ISSUE_TEMPLATE\Feature Request.yml = .github\ISSUE_TEMPLATE\Feature Request.yml
+ .github\ISSUE_TEMPLATE\Question.yml = .github\ISSUE_TEMPLATE\Question.yml
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B4833145-90B3-410E-9240-510B32E5FDA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B4833145-90B3-410E-9240-510B32E5FDA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B4833145-90B3-410E-9240-510B32E5FDA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B4833145-90B3-410E-9240-510B32E5FDA4}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9A69EEE4-F7D2-4693-B557-E4D338F241C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9A69EEE4-F7D2-4693-B557-E4D338F241C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9A69EEE4-F7D2-4693-B557-E4D338F241C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9A69EEE4-F7D2-4693-B557-E4D338F241C4}.Release|Any CPU.Build.0 = Release|Any CPU
+ {EA632DA8-39FA-4181-8475-7D01FB5EA480}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EA632DA8-39FA-4181-8475-7D01FB5EA480}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EA632DA8-39FA-4181-8475-7D01FB5EA480}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EA632DA8-39FA-4181-8475-7D01FB5EA480}.Release|Any CPU.Build.0 = Release|Any CPU
+ {64B00F65-B625-47E3-BD4C-779556DEA018}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {64B00F65-B625-47E3-BD4C-779556DEA018}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {64B00F65-B625-47E3-BD4C-779556DEA018}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {64B00F65-B625-47E3-BD4C-779556DEA018}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C0A69C38-9A77-4875-B3A9-9F170365D772}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C0A69C38-9A77-4875-B3A9-9F170365D772}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C0A69C38-9A77-4875-B3A9-9F170365D772}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C0A69C38-9A77-4875-B3A9-9F170365D772}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F19C565A-047C-4C91-AE2C-43687C9193FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F19C565A-047C-4C91-AE2C-43687C9193FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F19C565A-047C-4C91-AE2C-43687C9193FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F19C565A-047C-4C91-AE2C-43687C9193FE}.Release|Any CPU.Build.0 = Release|Any CPU
+ {109EAE14-6424-42F8-9877-0AB958A70E02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {109EAE14-6424-42F8-9877-0AB958A70E02}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {109EAE14-6424-42F8-9877-0AB958A70E02}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {109EAE14-6424-42F8-9877-0AB958A70E02}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9B95B4AD-E26A-40A1-A159-C75FB53C0821}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9B95B4AD-E26A-40A1-A159-C75FB53C0821}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9B95B4AD-E26A-40A1-A159-C75FB53C0821}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9B95B4AD-E26A-40A1-A159-C75FB53C0821}.Release|Any CPU.Build.0 = Release|Any CPU
+ {161F477E-4963-45B2-A0AD-CB7DB9A445FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {161F477E-4963-45B2-A0AD-CB7DB9A445FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {161F477E-4963-45B2-A0AD-CB7DB9A445FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {161F477E-4963-45B2-A0AD-CB7DB9A445FA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3E62CA06-4823-412D-99B6-231B76C8CB71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3E62CA06-4823-412D-99B6-231B76C8CB71}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3E62CA06-4823-412D-99B6-231B76C8CB71}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3E62CA06-4823-412D-99B6-231B76C8CB71}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4FF52EAA-D14E-4BFB-939C-FB79A968E2AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4FF52EAA-D14E-4BFB-939C-FB79A968E2AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4FF52EAA-D14E-4BFB-939C-FB79A968E2AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4FF52EAA-D14E-4BFB-939C-FB79A968E2AC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C01864D0-AE4F-404C-BAF3-626974FC7290}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C01864D0-AE4F-404C-BAF3-626974FC7290}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C01864D0-AE4F-404C-BAF3-626974FC7290}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C01864D0-AE4F-404C-BAF3-626974FC7290}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C47DB8DA-5534-4A74-ACA1-C1AC9D1FAB4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C47DB8DA-5534-4A74-ACA1-C1AC9D1FAB4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C47DB8DA-5534-4A74-ACA1-C1AC9D1FAB4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C47DB8DA-5534-4A74-ACA1-C1AC9D1FAB4A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {74FA9495-EBAA-4204-9D9A-4BDD025A637A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {74FA9495-EBAA-4204-9D9A-4BDD025A637A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {74FA9495-EBAA-4204-9D9A-4BDD025A637A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {74FA9495-EBAA-4204-9D9A-4BDD025A637A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {68302AAF-A2BA-4B15-8D63-AE03C641D38A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {68302AAF-A2BA-4B15-8D63-AE03C641D38A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {68302AAF-A2BA-4B15-8D63-AE03C641D38A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {68302AAF-A2BA-4B15-8D63-AE03C641D38A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1229ED65-0C15-468B-A979-C41B52C68D65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1229ED65-0C15-468B-A979-C41B52C68D65}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1229ED65-0C15-468B-A979-C41B52C68D65}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1229ED65-0C15-468B-A979-C41B52C68D65}.Release|Any CPU.Build.0 = Release|Any CPU
+ {100C07C6-C68D-469F-9F15-139CB48CB7F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {100C07C6-C68D-469F-9F15-139CB48CB7F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {100C07C6-C68D-469F-9F15-139CB48CB7F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {100C07C6-C68D-469F-9F15-139CB48CB7F0}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {43F06962-0100-488C-8EF5-4735E85A545C} = {0BE1019D-F812-4B03-9A6F-E3073A1CF0C9}
+ {B4833145-90B3-410E-9240-510B32E5FDA4} = {43F06962-0100-488C-8EF5-4735E85A545C}
+ {75482B5D-21E2-4DBE-BE78-657ECF0D409F} = {0BE1019D-F812-4B03-9A6F-E3073A1CF0C9}
+ {9A69EEE4-F7D2-4693-B557-E4D338F241C4} = {75482B5D-21E2-4DBE-BE78-657ECF0D409F}
+ {EA632DA8-39FA-4181-8475-7D01FB5EA480} = {75482B5D-21E2-4DBE-BE78-657ECF0D409F}
+ {64B00F65-B625-47E3-BD4C-779556DEA018} = {75482B5D-21E2-4DBE-BE78-657ECF0D409F}
+ {C0A69C38-9A77-4875-B3A9-9F170365D772} = {75482B5D-21E2-4DBE-BE78-657ECF0D409F}
+ {F19C565A-047C-4C91-AE2C-43687C9193FE} = {75482B5D-21E2-4DBE-BE78-657ECF0D409F}
+ {109EAE14-6424-42F8-9877-0AB958A70E02} = {75482B5D-21E2-4DBE-BE78-657ECF0D409F}
+ {61050ECA-956C-4BE1-8187-781603DC35C1} = {29DBF993-B6A4-4FA6-9CAA-730B319C164E}
+ {9B95B4AD-E26A-40A1-A159-C75FB53C0821} = {29DBF993-B6A4-4FA6-9CAA-730B319C164E}
+ {B47DBA4E-A9DA-4830-8EED-CFA0B798740C} = {29DBF993-B6A4-4FA6-9CAA-730B319C164E}
+ {C309DD88-CE7C-4E8B-A068-0D4BDF824A02} = {B47DBA4E-A9DA-4830-8EED-CFA0B798740C}
+ {161F477E-4963-45B2-A0AD-CB7DB9A445FA} = {B75F7FED-DAA6-41DC-ACBA-2193B9E0A685}
+ {3E62CA06-4823-412D-99B6-231B76C8CB71} = {B47DBA4E-A9DA-4830-8EED-CFA0B798740C}
+ {B75F7FED-DAA6-41DC-ACBA-2193B9E0A685} = {61050ECA-956C-4BE1-8187-781603DC35C1}
+ {D301D535-E35D-49E7-ADD7-F45D4CF9604B} = {61050ECA-956C-4BE1-8187-781603DC35C1}
+ {4FF52EAA-D14E-4BFB-939C-FB79A968E2AC} = {D301D535-E35D-49E7-ADD7-F45D4CF9604B}
+ {5E0267C1-E1B1-471A-951C-4AC894F870B8} = {29DBF993-B6A4-4FA6-9CAA-730B319C164E}
+ {1B31C12C-5D18-4675-8378-FBD9EEEF3793} = {5E0267C1-E1B1-471A-951C-4AC894F870B8}
+ {C01864D0-AE4F-404C-BAF3-626974FC7290} = {1B31C12C-5D18-4675-8378-FBD9EEEF3793}
+ {BDE3D3B9-8291-4AE9-B8DA-868CEBCBDC4D} = {5E0267C1-E1B1-471A-951C-4AC894F870B8}
+ {C47DB8DA-5534-4A74-ACA1-C1AC9D1FAB4A} = {BDE3D3B9-8291-4AE9-B8DA-868CEBCBDC4D}
+ {7C5D334A-FBCF-42E9-8E08-99C6894D9A4D} = {5E0267C1-E1B1-471A-951C-4AC894F870B8}
+ {74FA9495-EBAA-4204-9D9A-4BDD025A637A} = {7C5D334A-FBCF-42E9-8E08-99C6894D9A4D}
+ {68302AAF-A2BA-4B15-8D63-AE03C641D38A} = {BDE3D3B9-8291-4AE9-B8DA-868CEBCBDC4D}
+ {1229ED65-0C15-468B-A979-C41B52C68D65} = {BDE3D3B9-8291-4AE9-B8DA-868CEBCBDC4D}
+ {100C07C6-C68D-469F-9F15-139CB48CB7F0} = {BDE3D3B9-8291-4AE9-B8DA-868CEBCBDC4D}
+ {1706E43D-AC19-4FBB-9BFB-18A8B195580A} = {5FE82369-DEF2-4136-B74F-6E86DB91050E}
+ {24CCC156-046B-4600-9DB0-FC3269A18747} = {5FE82369-DEF2-4136-B74F-6E86DB91050E}
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {2E4F7126-B772-42CB-8F90-93B221ED0A72}
+ EndGlobalSection
+EndGlobal
diff --git a/docfx/.gitignore b/docfx/.gitignore
new file mode 100644
index 0000000..9780d95
--- /dev/null
+++ b/docfx/.gitignore
@@ -0,0 +1,3 @@
+# Ignore assets generated at build time
+_site/
+api/
\ No newline at end of file
diff --git a/docfx/README.md b/docfx/README.md
new file mode 100644
index 0000000..fead9e0
--- /dev/null
+++ b/docfx/README.md
@@ -0,0 +1,25 @@
+# ASP.NET Core SDK - DocFX Documentation
+The code in the `/docfx` folder is used to generate the documentation for the Sitecore ASP.NET Core SDK. The documentation is generated using [DocFX](https://dotnet.github.io/docfx/).
+
+## Building the documentation locally
+You can build and run this documentation locally by running the following commands
+
+### First time setup
+```dotnetcli
+dotnet tool update -g docfx
+```
+
+### Subsequent runs
+:warning: Ensure you are in the `/docfx` folder
+
+#### Run the documentation local server
+```dotnetcli
+docfx docfx.json --serve
+```
+
+You will then be able to access the documentation site at [http://localhost:8080](http://localhost:8080)
+
+#### Build the documentation
+```dotnetcli
+docfx docfx.json
+```
\ No newline at end of file
diff --git a/docfx/docfx.json b/docfx/docfx.json
new file mode 100644
index 0000000..76b06bc
--- /dev/null
+++ b/docfx/docfx.json
@@ -0,0 +1,49 @@
+{
+ "metadata": [
+ {
+ "src": [
+ {
+ "src": "../src",
+ "files": [
+ "**/*.csproj"
+ ]
+ }
+ ],
+ "dest": "api"
+ }
+ ],
+ "build": {
+ "content": [
+ {
+ "files": [
+ "**/*.{md,yml}"
+ ],
+ "exclude": [
+ "_site/**"
+ ]
+ }
+ ],
+ "resource": [
+ {
+ "files": [
+ "images/**"
+ ]
+ }
+ ],
+ "output": "_site",
+ "template": [
+ "default",
+ "modern",
+ "template"
+ ],
+ "globalMetadata": {
+ "_appName": "ASP.NET Core SDK",
+ "_appTitle": "ASP.NET Core SDK",
+ "_appLogoPath": "images/Sitecore-Icon.png",
+ "_appFaviconPath": "images/Sitecore-Icon.png",
+ "_enableSearch": true,
+ "_disableBreadcrumb": true,
+ "pdf": false
+ }
+ }
+}
\ No newline at end of file
diff --git a/docfx/images/Sitecore-Icon.png b/docfx/images/Sitecore-Icon.png
new file mode 100644
index 0000000..3c2026d
Binary files /dev/null and b/docfx/images/Sitecore-Icon.png differ
diff --git a/docfx/images/Sitecore-Logo.svg b/docfx/images/Sitecore-Logo.svg
new file mode 100644
index 0000000..304902a
--- /dev/null
+++ b/docfx/images/Sitecore-Logo.svg
@@ -0,0 +1,19 @@
+
+
\ No newline at end of file
diff --git a/docfx/index.md b/docfx/index.md
new file mode 100644
index 0000000..deae8f1
--- /dev/null
+++ b/docfx/index.md
@@ -0,0 +1,10 @@
+---
+_layout: landing
+---
+
+![Sitecore Logo](./images/Sitecore-Icon.png)
+
+# ASP.NET Core SDK - API Documentation
+This documentation is for the Sitecore ASP.NET Core SDK. The SDK contains a set of libraries that enable you to render Sitecore content in ASP.NET Core.
+
+To see guides on how to leverage the SDK in your Sitecore XM/XP or Sitecore XM Cloud projects, you can refer to the [Sitecore Documentation Site](https://doc.sitecore.com).
\ No newline at end of file
diff --git a/docfx/overview/index.md b/docfx/overview/index.md
new file mode 100644
index 0000000..a419ae7
--- /dev/null
+++ b/docfx/overview/index.md
@@ -0,0 +1,83 @@
+---
+_layout: landing
+---
+
+# Overview
+The ASP.NET Core SDK is built to help developers leverage Sitecore Layout Data in their applications, to build layouts and hydrate components.
+
+## Data flow
+The SDK enables ASP.NET Core Applications to connect to a Sitecore instance of XM/XP or XMC and retrieve Layout Data. The Layout Data is a JSON object that represents the structure of a page in Sitecore. The Layout Data is used to render the page in the application.
+
+### Basic Execution Sequence
+The ASP.NET CoreSDK uses GraphQL to retrieve Layout Data in JSON format. When using Sitecore XM Cloud or Sitecore Experience Edge, the SDK connects to the Sitecore Experience Edge service to retrieve the Layout Data.
+When working with Sitecore XM or Sitecore XP CD servers, the SDK connects to the Sitecore Layout Service to retrieve the Layout Data.
+
+Below you can see a basic sequence diagram of the execution flow, showing how the data flows between the browser, the ASP.NET Core Application, and the Experience Edge or Layout Service.
+
+```mermaid
+sequenceDiagram
+ Browser->>ASP.NET Core Application: Page Request
+ ASP.NET Core Application-->>Experience Edge / Layout Service: GraphQL Request
+ Experience Edge / Layout Service-->>ASP.NET Core Application: Layout Data JSON
+ ASP.NET Core Application->>Browser: Page HTML
+```
+
+### Full Execution Sequence
+The full execution sequence is more detailed and shows how the Layout Data is used to render the page in the application. The sequence diagram below shows the full execution flow, including the rendering of the page in the application.
+
+```mermaid
+sequenceDiagram
+ actor User
+ participant Browser
+ box ASP.NET Core Application
+ participant App as Standard Middleware
+ participant Middleware as Rendering Engine Middleware
+ participant Rendering
+ participant Client as Layout Service Client
+ end
+ participant Sitecore as Experience Edge or Layout Service
+
+ User->>Browser: Browse to URI
+ Browser-->>App: HTTP Request
+ activate App
+ App->>App: Resolve Controller
+ App->>App: Resolve Action
+ note right of App: Regular MVC Rendering happens if there is no [UseSitecoreRendering] attribute on the action
+ opt has [UseSitecoreRendering] attribute
+ App->>Middleware: Execute
+ deactivate App
+ activate Middleware
+ Middleware-->>Client: Layout Service Request
+ activate Client
+ Client-->>+Sitecore: GraphQL Request
+ Sitecore-->>-Client: GraphQL Response
+ Client-->>Middleware: Layout Service Response
+ deactivate Client
+ Middleware->>Middleware: Update HTTP Context
+ Middleware-->>Rendering: HTTP+Rendering Context
+ deactivate Middleware
+ activate Rendering
+ Rendering->>Rendering: Invoke Action
+ Rendering->>Rendering: Execute Razor View
+ Rendering->>Rendering:
+ loop Resolve Component
+ alt is Model Bound View
+ Rendering->>Rendering: Model Binding
+ Rendering->>Rendering: Execute Razor View
+ else is Custom View Component
+ Rendering->>Rendering: Model Binding
+ Rendering->>Rendering: Execute Razor View
+ else is Partial View
+ Rendering->>Rendering: Model Binding
+ Rendering->>Rendering: Execute Razor View
+ end
+ end
+ note right of Rendering: Executes recursively for each placeholder
+ Rendering-->>App: HTML
+ deactivate Rendering
+ activate App
+ end
+ App-->>Browser: HTTP Response
+ deactivate App
+ Browser->>User: Display Page
+```
\ No newline at end of file
diff --git a/docfx/template/public/main.css b/docfx/template/public/main.css
new file mode 100644
index 0000000..b3d0d0a
--- /dev/null
+++ b/docfx/template/public/main.css
@@ -0,0 +1,7 @@
+img#logo {
+ width: 50px
+}
+
+article .logo {
+ margin-bottom: 25px;
+}
\ No newline at end of file
diff --git a/docfx/toc.yml b/docfx/toc.yml
new file mode 100644
index 0000000..0be4b20
--- /dev/null
+++ b/docfx/toc.yml
@@ -0,0 +1,6 @@
+- name: Home
+ href: index.md
+- name: Overview
+ href: overview/index.md
+- name: API
+ href: api/
\ No newline at end of file
diff --git a/nuget.config b/nuget.config
new file mode 100644
index 0000000..ae9403e
--- /dev/null
+++ b/nuget.config
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
new file mode 100644
index 0000000..be8681a
--- /dev/null
+++ b/src/Directory.Build.props
@@ -0,0 +1,31 @@
+
+
+
+
+
+ net8.0
+ enable
+ enable
+ true
+ $(NoWarn.Replace(';CS1591',''));CS7035
+
+ sc-ivanlieckens
+ Sitecore
+ https://github.com/Sitecore/ASP.NET-Core-Rendering-SDK
+ sitecore
+ Apache-2.0
+ True
+ icon.png
+
+
+
+
+ GlobalSuppressions.cs
+
+
+ True
+ \
+
+
+
+
\ No newline at end of file
diff --git a/src/GlobalSuppressions.cs b/src/GlobalSuppressions.cs
new file mode 100644
index 0000000..188f7b1
--- /dev/null
+++ b/src/GlobalSuppressions.cs
@@ -0,0 +1,13 @@
+// This file is used by Code Analysis to maintain SuppressMessage
+// attributes that are applied to this project.
+// Project-level suppressions either have no target or are given
+// a specific target and scoped to a namespace, type, member, etc.
+
+using System.Diagnostics.CodeAnalysis;
+
+[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this", Justification = "Not required.")]
+[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:Using directives should be placed correctly", Justification = "Type confusion should not occur.")]
+[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1206:Declaration keywords should follow order", Justification = "ReSharper ordering rules used.")]
+[assembly: SuppressMessage("StyleCop.CSharp.NamingRules", "SA1309:Field names should not begin with underscore", Justification = "Underscores are used for private class variables.")]
+[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1413:Use trailing comma in multi-line initializers", Justification = "Not required.")]
+[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "No headers required.")]
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Configuration/ExperienceEditorMarkerService.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Configuration/ExperienceEditorMarkerService.cs
new file mode 100644
index 0000000..36b68ea
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Configuration/ExperienceEditorMarkerService.cs
@@ -0,0 +1,6 @@
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.Configuration;
+
+///
+/// Marker service used to identify when experience editor services have been registered.
+///
+internal class ExperienceEditorMarkerService;
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Configuration/ExperienceEditorOptions.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Configuration/ExperienceEditorOptions.cs
new file mode 100644
index 0000000..3303998
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Configuration/ExperienceEditorOptions.cs
@@ -0,0 +1,25 @@
+using Microsoft.AspNetCore.Http;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Response;
+
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.Configuration;
+
+///
+/// The options to configure the experience editor middleware.
+///
+public class ExperienceEditorOptions
+{
+ ///
+ /// Gets or sets the endpoint that represent editing application URLs.
+ ///
+ public string Endpoint { get; set; } = "/jss-render";
+
+ ///
+ /// Gets or sets the action list to configure the handler for Experience Editor custom post requests.
+ ///
+ public ICollection> ItemMappings { get; set; } = [];
+
+ ///
+ /// Gets or sets the Jss Editing Secret.
+ ///
+ public string JssEditingSecret { get; set; } = string.Empty;
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/ExperienceEditorConstants.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/ExperienceEditorConstants.cs
new file mode 100644
index 0000000..9325e4e
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/ExperienceEditorConstants.cs
@@ -0,0 +1,20 @@
+using Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers;
+
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor;
+
+///
+/// Various constants relevant to the Experience Editor.
+///
+public static class ExperienceEditorConstants
+{
+ ///
+ /// Constants relevant to the Sitecore tag helpers.
+ ///
+ public static class SitecoreTagHelpers
+ {
+ ///
+ /// The HTML tag used by the tag helper.
+ ///
+ public const string EditFrameHtmlTag = "sc-edit-frame";
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Extensions/ExperienceEditorAppConfigurationExtensions.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Extensions/ExperienceEditorAppConfigurationExtensions.cs
new file mode 100644
index 0000000..f162356
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Extensions/ExperienceEditorAppConfigurationExtensions.cs
@@ -0,0 +1,60 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.DependencyInjection;
+using Sitecore.AspNetCore.SDK.ExperienceEditor.Configuration;
+using Sitecore.AspNetCore.SDK.ExperienceEditor.Middleware;
+using Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers;
+using Sitecore.AspNetCore.SDK.RenderingEngine.Interfaces;
+
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.Extensions;
+
+///
+/// Configuration helpers for ExperienceEditor functionality.
+///
+public static class ExperienceEditorAppConfigurationExtensions
+{
+ ///
+ /// Registers the Sitecore Experience Editor middleware into the .
+ ///
+ /// The instance of the to extend.
+ /// The so that additional calls can be chained.
+ public static IApplicationBuilder UseSitecoreExperienceEditor(this IApplicationBuilder app)
+ {
+ ArgumentNullException.ThrowIfNull(app);
+
+ object? experienceEditorMarker = app.ApplicationServices.GetService(typeof(ExperienceEditorMarkerService));
+ if (experienceEditorMarker != null)
+ {
+ app.UseMiddleware();
+ }
+
+ return app;
+ }
+
+ ///
+ /// Adds the Sitecore Experience Editor support services to the .
+ ///
+ /// The to add services to.
+ /// Configures the options.
+ /// The so that additional calls can be chained.
+ public static ISitecoreRenderingEngineBuilder WithExperienceEditor(this ISitecoreRenderingEngineBuilder serviceBuilder, Action? options = null)
+ {
+ ArgumentNullException.ThrowIfNull(serviceBuilder);
+
+ IServiceCollection services = serviceBuilder.Services;
+ if (services.Any(s => s.ServiceType == typeof(ExperienceEditorMarkerService)))
+ {
+ return serviceBuilder;
+ }
+
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+
+ if (options != null)
+ {
+ services.Configure(options);
+ }
+
+ return serviceBuilder;
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Extensions/ExperienceEditorOptionsExtensions.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Extensions/ExperienceEditorOptionsExtensions.cs
new file mode 100644
index 0000000..3859da0
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Extensions/ExperienceEditorOptionsExtensions.cs
@@ -0,0 +1,27 @@
+using Microsoft.AspNetCore.Http;
+using Sitecore.AspNetCore.SDK.ExperienceEditor.Configuration;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Response;
+
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.Extensions;
+
+///
+/// Extensions to help configure .
+///
+public static class ExperienceEditorOptionsExtensions
+{
+ ///
+ /// Adds a custom mapping action.
+ ///
+ /// The to configure.
+ /// The mapping action to configure .
+ /// The so that additional calls can be chained.
+ public static ExperienceEditorOptions MapToRequest(this ExperienceEditorOptions options, Action mapAction)
+ {
+ ArgumentNullException.ThrowIfNull(options);
+ ArgumentNullException.ThrowIfNull(mapAction);
+
+ options.ItemMappings.Add(mapAction);
+
+ return options;
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Mappers/SitecoreLayoutResponseMapper.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Mappers/SitecoreLayoutResponseMapper.cs
new file mode 100644
index 0000000..5c5e063
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Mappers/SitecoreLayoutResponseMapper.cs
@@ -0,0 +1,50 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Options;
+using Sitecore.AspNetCore.SDK.ExperienceEditor.Configuration;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Response;
+
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.Mappers;
+
+///
+/// Class that maps the layout response according to the options.
+///
+internal class SitecoreLayoutResponseMapper
+{
+ private readonly ICollection> _handlers;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The instance.
+ public SitecoreLayoutResponseMapper(IOptions options)
+ {
+ ArgumentNullException.ThrowIfNull(options);
+ _handlers = options.Value.ItemMappings;
+ }
+
+ ///
+ /// Maps the route to a request path.
+ ///
+ /// Layout Response.
+ /// Sitecore Path.
+ /// Request data.
+ /// Path of the request.
+ public string? MapRoute(SitecoreLayoutResponseContent response, string scPath, HttpRequest request)
+ {
+ ArgumentNullException.ThrowIfNull(response);
+ ArgumentException.ThrowIfNullOrWhiteSpace(scPath);
+ ArgumentNullException.ThrowIfNull(request);
+
+ if (_handlers.Count == 0)
+ {
+ return scPath;
+ }
+
+ foreach (Action handler in _handlers)
+ {
+ handler.Invoke(response, scPath, request);
+ }
+
+ return request.Path.Value;
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Middleware/ExperienceEditorMiddleware.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Middleware/ExperienceEditorMiddleware.cs
new file mode 100644
index 0000000..e7aaed4
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Middleware/ExperienceEditorMiddleware.cs
@@ -0,0 +1,219 @@
+using System.Net;
+using System.Text.Json;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using Sitecore.AspNetCore.SDK.ExperienceEditor.Configuration;
+using Sitecore.AspNetCore.SDK.ExperienceEditor.Mappers;
+using Sitecore.AspNetCore.SDK.ExperienceEditor.Models;
+using Sitecore.AspNetCore.SDK.LayoutService.Client;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Response;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Serialization;
+using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions;
+using Sitecore.AspNetCore.SDK.RenderingEngine.Rendering;
+
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.Middleware;
+
+///
+/// The Experience Editor middleware implementation that handles POST requests from the Sitecore Experience Editor
+/// and wraps the response HTML in a JSON format.
+///
+///
+/// Initializes a new instance of the class.
+///
+/// The next middleware to call.
+/// The experience editor configuration options.
+/// A configured instance of .
+/// The to use for logging.
+public class ExperienceEditorMiddleware(RequestDelegate next, IOptions options, ISitecoreLayoutSerializer serializer, ILogger logger)
+{
+ private readonly ISitecoreLayoutSerializer _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
+ private readonly RequestDelegate _next = next ?? throw new ArgumentNullException(nameof(next));
+ private readonly ExperienceEditorOptions _options = options != null ? options.Value : throw new ArgumentNullException(nameof(options));
+ private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger));
+ private readonly SitecoreLayoutResponseMapper _responseMapper = new(options);
+
+ ///
+ /// The middleware Invoke method.
+ ///
+ /// The current .
+ /// A Task to support async calls.
+ public async Task Invoke(HttpContext httpContext)
+ {
+ ArgumentNullException.ThrowIfNull(httpContext);
+
+ if (IsExperienceEditorRequest(httpContext.Request))
+ {
+ ExperienceEditorPostModel? postModel = await TryParseContentFromRequestBodyAsync(httpContext).ConfigureAwait(false);
+
+ if (postModel == null || !CheckJssEditingSecret(postModel, httpContext) || !TrySetHttpContextFeaturesForNextHandler(httpContext, postModel))
+ {
+ return;
+ }
+
+ Stream realResponseStream = httpContext.Response.Body;
+ try
+ {
+ MemoryStream tmpResponseBuffer = new();
+
+ httpContext.Response.Body = tmpResponseBuffer;
+
+ await _next(httpContext).ConfigureAwait(false);
+
+ tmpResponseBuffer.Position = 0;
+ string responseBody = await new StreamReader(tmpResponseBuffer).ReadToEndAsync().ConfigureAwait(false);
+
+ await using StreamWriter realResponseWriter = new(realResponseStream);
+ await realResponseWriter.WriteAsync("{\"html\":").ConfigureAwait(false);
+
+ string html = JsonSerializer.Serialize(responseBody);
+ await realResponseWriter.WriteAsync(html).ConfigureAwait(false);
+ await realResponseWriter.WriteAsync("}").ConfigureAwait(false);
+ }
+ finally
+ {
+ httpContext.Response.Body = realResponseStream;
+ }
+ }
+ else
+ {
+ await _next(httpContext).ConfigureAwait(false);
+ }
+ }
+
+ private static async Task ParseContentFromRequestBodyAsync(HttpContext context)
+ {
+ using StreamReader reader = new(context.Request.Body);
+ string body = await reader.ReadToEndAsync().ConfigureAwait(false);
+ if (string.IsNullOrEmpty(body))
+ {
+ throw new FormatException("Empty request body");
+ }
+
+ return JsonSerializer.Deserialize(body, JsonLayoutServiceSerializer.GetDefaultSerializerOptions()) ?? new ExperienceEditorPostModel();
+ }
+
+ private static string GetSitecoreItemPathFromRequestBody(ExperienceEditorPostModel postModel)
+ {
+ string? result = string.Empty;
+ if (JsonDocument.Parse(postModel.Args[1]).RootElement.TryGetProperty(LayoutServiceClientConstants.Serialization.SitecoreDataPropertyName, out JsonElement sitecore)
+ && sitecore.TryGetProperty(LayoutServiceClientConstants.Serialization.ContextPropertyName, out JsonElement context)
+ && context.TryGetProperty("itemPath", out JsonElement path))
+ {
+ result = path.GetString();
+ }
+
+ if (string.IsNullOrWhiteSpace(result)
+ && JsonDocument.Parse(postModel.Args[2]).RootElement.TryGetProperty("httpContext", out JsonElement httpContext)
+ && httpContext.TryGetProperty("request", out JsonElement request)
+ && request.TryGetProperty("path", out path))
+ {
+ // keep backwards compatibility in case people use an older JSS version that doesn't send the path in the context.
+ result = path.GetString();
+ }
+
+ return result ?? string.Empty;
+ }
+
+ private bool IsExperienceEditorRequest(HttpRequest httpRequest)
+ {
+ ArgumentNullException.ThrowIfNull(httpRequest);
+ return httpRequest.Method == HttpMethods.Post && httpRequest.Path.Value!.Equals(_options.Endpoint, StringComparison.InvariantCultureIgnoreCase);
+ }
+
+ private SitecoreLayoutResponseContent GetSitecoreLayoutContentFromRequestBody(ExperienceEditorPostModel postModel)
+ {
+ return _serializer.Deserialize(postModel.Args[1]) ?? new SitecoreLayoutResponseContent();
+ }
+
+ private string GetMappedPath(string scPath, SitecoreLayoutResponseContent response, HttpRequest request)
+ {
+ string? customMappedPath = _responseMapper.MapRoute(response, scPath, request);
+ return string.IsNullOrWhiteSpace(customMappedPath) ? scPath : customMappedPath;
+ }
+
+ private bool TrySetHttpContextFeaturesForNextHandler(HttpContext httpContext, ExperienceEditorPostModel postModel)
+ {
+ try
+ {
+ // parse POST body and set rendering context
+ SitecoreLayoutResponseContent content = GetSitecoreLayoutContentFromRequestBody(postModel);
+
+ SitecoreRenderingContext scContext = new()
+ {
+ Response = new SitecoreLayoutResponse([])
+ {
+ Content = content
+ }
+ };
+
+ httpContext.SetSitecoreRenderingContext(scContext);
+
+ // Changing POST request to GET stream
+ httpContext.Request.Method = HttpMethods.Get;
+
+ // Replace the request path with the item path from request metadata.
+ // This is needed to support different routing or other kinds of path dependent logic.
+ string scPath = GetSitecoreItemPathFromRequestBody(postModel);
+ if (!string.IsNullOrWhiteSpace(scPath))
+ {
+ httpContext.Request.Path = GetMappedPath(scPath, content, httpContext.Request);
+ }
+ else
+ {
+ httpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
+ _logger.LogError("Error parsing Layout content from POST request: Empty Item path.");
+ return false;
+ }
+ }
+
+ // Disabled catching general exceptions because all exceptions in request parsing shall be treated as bad requests.
+ catch (Exception exception)
+ {
+ httpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
+ _logger.LogError(exception, "Error parsing Layout content from POST request");
+ return false;
+ }
+
+ return true;
+ }
+
+ private bool CheckJssEditingSecret(ExperienceEditorPostModel postModel, HttpContext httpContext)
+ {
+ string localSecret = _options.JssEditingSecret;
+ if (string.IsNullOrEmpty(localSecret))
+ {
+ httpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
+ _logger.LogError("The JSS_EDITING_SECRET environment variable is missing or invalid.");
+ return false;
+ }
+
+ string? secretFromRequest = postModel.JssEditingSecret;
+
+ bool result = localSecret == secretFromRequest;
+ if (!result)
+ {
+ httpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
+ _logger.LogError("Missing or invalid secret");
+ }
+
+ return result;
+ }
+
+ private async Task TryParseContentFromRequestBodyAsync(HttpContext httpContext)
+ {
+ ExperienceEditorPostModel postModel;
+ try
+ {
+ postModel = await ParseContentFromRequestBodyAsync(httpContext).ConfigureAwait(false);
+ }
+ catch (Exception exception)
+ {
+ httpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
+ _logger.LogError(exception, "Error parsing POST request");
+ return null;
+ }
+
+ return postModel;
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Models/ExperienceEditorPostModel.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Models/ExperienceEditorPostModel.cs
new file mode 100644
index 0000000..c1038ab
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Models/ExperienceEditorPostModel.cs
@@ -0,0 +1,53 @@
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.Models;
+
+///
+/// Represents the model used to store the experience editor post.
+///
+public class ExperienceEditorPostModel
+{
+ ///
+ /// Gets or sets the Id which has the name of the JSS app in the content tree/configuration.
+ ///
+ public string? Id { get; set; }
+
+ ///
+ /// Gets or sets the function name.
+ ///
+ public string? FunctionName { get; set; }
+
+ ///
+ /// Gets or sets the module name.
+ ///
+ public string? ModuleName { get; set; }
+
+ ///
+ /// Gets or sets the Args which is an array that contains JSON strings.
+ ///
+ ///
+ /// By default, the array has the following structure:
+ ///
+ /// {
+ /// request path,
+ /// serialized data {
+ /// sitecore (a root property) {
+ /// context (contains additional details, like language, site, user and the item path),
+ /// route (contains the item's properties and layout details) } },
+ /// serialized view bag {
+ /// language,
+ /// dictionary (localization),
+ /// httpContext {
+ /// request {
+ /// url,
+ /// path,
+ /// querystring (a key-value dictionary ),
+ /// userAgent } } } }
+ ///
+ /// The item path is the path that would be seen, when navigating to it on frontend, i.e. it is a site relative link.
+ ///
+ public List Args { get; set; } = [];
+
+ ///
+ /// Gets or sets the Jss Editing Secret.
+ ///
+ public string? JssEditingSecret { get; set; }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Properties/Resources.Designer.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..1cdd454
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Properties/Resources.Designer.cs
@@ -0,0 +1,72 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.Properties {
+ using System;
+
+
+ ///
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ ///
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ ///
+ /// Returns the cached ResourceManager instance used by this class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Sitecore.AspNetCore.SDK.ExperienceEditor.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to ViewContext parameter cannot be null..
+ ///
+ internal static string Exception_ViewContextCannotBeNull {
+ get {
+ return ResourceManager.GetString("Exception_ViewContextCannotBeNull", resourceCulture);
+ }
+ }
+ }
+}
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Properties/Resources.resx b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Properties/Resources.resx
new file mode 100644
index 0000000..53d3fe2
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Properties/Resources.resx
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ ViewContext parameter cannot be null.
+
+
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Sitecore.AspNetCore.SDK.ExperienceEditor.csproj b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Sitecore.AspNetCore.SDK.ExperienceEditor.csproj
new file mode 100644
index 0000000..e4cebdd
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/Sitecore.AspNetCore.SDK.ExperienceEditor.csproj
@@ -0,0 +1,33 @@
+
+
+
+ Sitecore Editing Host
+ .NET SDK for creating a Sitecore Headless Editing Host supporting Experience Editor
+
+
+
+
+
+
+
+
+ <_Parameter1>Sitecore.AspNetCore.SDK.ExperienceEditor.Tests
+
+
+
+
+
+ True
+ True
+ Resources.resx
+
+
+
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+
+
+
+
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/ChromeDataBuilder.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/ChromeDataBuilder.cs
new file mode 100644
index 0000000..e20c7ae
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/ChromeDataBuilder.cs
@@ -0,0 +1,120 @@
+using Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers.Model;
+
+// ReSharper disable StringLiteralTypo
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers;
+
+///
+internal class ChromeDataBuilder : IChromeDataBuilder
+{
+ ///
+ public ChromeCommand MapButtonToCommand(EditButtonBase button, string? itemId, IDictionary? parameters)
+ {
+ if (button is DividerEditButton dividerEditButton)
+ {
+ return new ChromeCommand
+ {
+ Click = "chrome:dummy",
+ Header = dividerEditButton.Header,
+ Icon = dividerEditButton.Icon,
+ IsDivider = true,
+ Tooltip = null,
+ Type = "separator"
+ };
+ }
+
+ if (button is WebEditButton webEditButton && !string.IsNullOrWhiteSpace(webEditButton.Click))
+ {
+ return CommandBuilder(webEditButton, itemId, parameters);
+ }
+
+ FieldEditButton? fieldEditButton = button as FieldEditButton;
+ string fieldsString = string.Join('|', fieldEditButton?.Fields ?? []);
+ webEditButton = new WebEditButton
+ {
+ Click = $"webedit:fieldeditor(command={DefaultEditFrameButtonIds.Edit},fields={fieldsString})",
+ Tooltip = button.Tooltip,
+ Header = button.Header,
+ Icon = button.Icon,
+ };
+
+ return CommandBuilder(webEditButton, itemId, parameters);
+ }
+
+ private static ChromeCommand CommandBuilder(WebEditButton button, string? itemId, IDictionary? frameParameters)
+ {
+ if (string.IsNullOrWhiteSpace(button.Click) ||
+ button.Click.StartsWith("javascript:", StringComparison.OrdinalIgnoreCase) ||
+ button.Click.StartsWith("chrome:", StringComparison.OrdinalIgnoreCase) ||
+ string.IsNullOrWhiteSpace(itemId))
+ {
+ return new ChromeCommand
+ {
+ IsDivider = false,
+ Type = button.Type,
+ Header = button.Header ?? string.Empty,
+ Icon = button.Icon ?? string.Empty,
+ Tooltip = button.Tooltip ?? string.Empty,
+ Click = button.Click ?? string.Empty,
+ };
+ }
+
+ string? message = button.Click;
+ Dictionary parameters = [];
+
+ // Extract any parameters already in the command
+ int length = button.Click.IndexOf('(', StringComparison.OrdinalIgnoreCase);
+ if (length >= 0)
+ {
+ int end = button.Click.IndexOf(')', StringComparison.OrdinalIgnoreCase);
+ if (end < 0)
+ {
+ throw new ArgumentException("Message with arguments must end with ).");
+ }
+
+ parameters = button.Click[(length + 1)..end]
+ .Split(',')
+ .Select(x => x.Trim())
+ .Aggregate(new Dictionary(), (previous, current) =>
+ {
+ string[] parts = current.Split('=');
+ previous[parts[0]] = parts.Length < 2
+ ? string.Empty
+ : parts[1];
+ return previous;
+ });
+
+ message = button.Click[..length];
+ }
+
+ parameters["id"] = itemId;
+
+ if (button.Parameters != null && button.Parameters.Any())
+ {
+ foreach ((string key, object? value) in button.Parameters)
+ {
+ parameters[key] = value?.ToString() ?? string.Empty;
+ }
+ }
+
+ if (frameParameters != null && frameParameters.Any())
+ {
+ foreach ((string key, object? value) in frameParameters)
+ {
+ parameters[key] = value?.ToString() ?? string.Empty;
+ }
+ }
+
+ string parameterString = string.Join(", ", parameters.Select(x => $"{x.Key}={x.Value}"));
+ string click = $"{message}({parameterString})";
+
+ return new ChromeCommand
+ {
+ IsDivider = false,
+ Type = button.Type,
+ Header = button.Header ?? string.Empty,
+ Icon = button.Icon ?? string.Empty,
+ Tooltip = button.Tooltip ?? string.Empty,
+ Click = $"javascript:Sitecore.PageModes.PageEditor.postRequest('{click}',null,false)"
+ };
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/ChromeDataSerializer.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/ChromeDataSerializer.cs
new file mode 100644
index 0000000..ee2cc08
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/ChromeDataSerializer.cs
@@ -0,0 +1,18 @@
+using System.Text.Json;
+
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers;
+
+///
+internal class ChromeDataSerializer : IChromeDataSerializer
+{
+ private static readonly JsonSerializerOptions DefaultSerializerOptions = new()
+ {
+ PropertyNamingPolicy = JsonNamingPolicy.CamelCase
+ };
+
+ ///
+ public string Serialize(Dictionary chromeData)
+ {
+ return JsonSerializer.Serialize(chromeData, DefaultSerializerOptions);
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/EditFrameTagHelper.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/EditFrameTagHelper.cs
new file mode 100644
index 0000000..33e164d
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/EditFrameTagHelper.cs
@@ -0,0 +1,122 @@
+using Microsoft.AspNetCore.Mvc.Rendering;
+using Microsoft.AspNetCore.Mvc.ViewFeatures;
+using Microsoft.AspNetCore.Razor.TagHelpers;
+using Sitecore.AspNetCore.SDK.ExperienceEditor.Properties;
+using Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers.Model;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Response.Model;
+using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions;
+using Sitecore.AspNetCore.SDK.RenderingEngine.Interfaces;
+
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers;
+
+///
+/// Tag helper for the Sitecore placeholder element.
+///
+///
+/// Initializes a new instance of the class.
+///
+/// An instance of .
+/// An instance of .
+[HtmlTargetElement(ExperienceEditorConstants.SitecoreTagHelpers.EditFrameHtmlTag)]
+public class EditFrameTagHelper(IChromeDataBuilder chromeDataBuilder, IChromeDataSerializer chromeDataSerializer)
+ : TagHelper
+{
+ private readonly IChromeDataBuilder _chromeDataBuilder = chromeDataBuilder ?? throw new ArgumentNullException(nameof(chromeDataBuilder));
+ private readonly IChromeDataSerializer _chromeDataSerializer = chromeDataSerializer ?? throw new ArgumentNullException(nameof(chromeDataSerializer));
+
+ ///
+ /// Gets or sets the current view context for the tag helper.
+ ///
+ [HtmlAttributeNotBound]
+ [ViewContext]
+ public ViewContext? ViewContext { get; set; }
+
+ ///
+ /// Gets or sets the title of edit frame.
+ ///
+ public string? Title { get; set; }
+
+ ///
+ /// Gets or sets the tooltip of edit frame.
+ ///
+ public string? Tooltip { get; set; }
+
+ ///
+ /// Gets or sets the CSS class which be applied for edit frame.
+ ///
+ public string? CssClass { get; set; }
+
+ ///
+ /// Gets or sets the collection of edit frame buttons.
+ ///
+ public IEnumerable? Buttons { get; set; }
+
+ ///
+ /// Gets or sets the data source of edit frame.
+ ///
+ public EditFrameDataSource? Source { get; set; }
+
+ ///
+ /// Gets or sets the parameters of edit frame.
+ ///
+ public IDictionary? Parameters { get; set; }
+
+ ///
+ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
+ {
+ ArgumentNullException.ThrowIfNull(context);
+ ArgumentNullException.ThrowIfNull(output);
+
+ SitecoreData? sitecoreData = GetSitecoreData();
+ output.TagName = string.Empty;
+
+ if (sitecoreData?.Context is not { IsEditing: true })
+ {
+ return;
+ }
+
+ Dictionary chromeData = [];
+ Dictionary frameProps = [];
+
+ if (Source != null)
+ {
+ string? databaseName = Source.DatabaseName ?? sitecoreData.Route?.DatabaseName;
+ string language = Source.Language ?? sitecoreData.Context.Language;
+
+ chromeData["contextItemUri"] = frameProps["sc_item"] = $"sitecore://{databaseName}/{Source.ItemId}?lang={language}";
+ }
+
+ frameProps["class"] = $"scLooseFrameZone {CssClass}".Trim();
+ chromeData["displayName"] = Title;
+ chromeData["expandedDisplayName"] = Tooltip;
+ chromeData["commands"] = Buttons?.Select(btn => _chromeDataBuilder.MapButtonToCommand(btn, Source?.ItemId, Parameters)).ToList();
+
+ TagBuilder chromeDataTagBuilder = new("span");
+ chromeDataTagBuilder.AddCssClass("scChromeData");
+ chromeDataTagBuilder.InnerHtml.Append(_chromeDataSerializer.Serialize(chromeData));
+
+ TagBuilder frameZoneTagBuilder = new("div");
+ foreach ((string key, string? value) in frameProps)
+ {
+ frameZoneTagBuilder.Attributes.Add(key, value);
+ }
+
+ frameZoneTagBuilder.InnerHtml.AppendHtml(chromeDataTagBuilder);
+
+ TagHelperContent? innerContent = await output.GetChildContentAsync().ConfigureAwait(false);
+ frameZoneTagBuilder.InnerHtml.AppendHtml(innerContent.GetContent());
+
+ output.Content.SetHtmlContent(frameZoneTagBuilder);
+ }
+
+ private SitecoreData? GetSitecoreData()
+ {
+ if (ViewContext == null)
+ {
+ throw new NullReferenceException(Resources.Exception_ViewContextCannotBeNull);
+ }
+
+ ISitecoreRenderingContext? renderingContext = ViewContext.HttpContext.GetSitecoreRenderingContext();
+ return renderingContext?.Response?.Content?.Sitecore;
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/IChromeDataBuilder.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/IChromeDataBuilder.cs
new file mode 100644
index 0000000..372e349
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/IChromeDataBuilder.cs
@@ -0,0 +1,18 @@
+using Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers.Model;
+
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers;
+
+///
+/// Contract for configuring Chrome Data clients.
+///
+public interface IChromeDataBuilder
+{
+ ///
+ /// Maps object to .
+ ///
+ /// The edit button to build a ChromeCommand.
+ /// The ID of the item the EditFrame is associated with.
+ /// Additional parameters passed to the EditFrame.
+ /// Instance of .
+ ChromeCommand MapButtonToCommand(EditButtonBase button, string? itemId, IDictionary? parameters);
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/IChromeDataSerializer.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/IChromeDataSerializer.cs
new file mode 100644
index 0000000..ea33093
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/IChromeDataSerializer.cs
@@ -0,0 +1,14 @@
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers;
+
+///
+/// Contract that supports serialization for the Chrome Data.
+///
+public interface IChromeDataSerializer
+{
+ ///
+ /// Serializes the given data to the string in JSON format.
+ ///
+ /// The data for serialization.
+ /// The JSON string.
+ string Serialize(Dictionary chromeData);
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/ChromeCommand.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/ChromeCommand.cs
new file mode 100644
index 0000000..fb9709f
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/ChromeCommand.cs
@@ -0,0 +1,37 @@
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers.Model;
+
+///
+/// This class contains fields for a command in the chrome data.
+///
+public class ChromeCommand
+{
+ ///
+ /// Gets or sets a value indicating whether is it divider or not.
+ ///
+ public bool IsDivider { get; set; }
+
+ ///
+ /// Gets or sets the type of command.
+ ///
+ public string? Type { get; set; }
+
+ ///
+ /// Gets or sets the header of command.
+ ///
+ public string Header { get; set; } = default!;
+
+ ///
+ /// Gets or sets the icon path of command.
+ ///
+ public string Icon { get; set; } = default!;
+
+ ///
+ /// Gets or sets the tooltip of command.
+ ///
+ public string? Tooltip { get; set; }
+
+ ///
+ /// Gets or sets the click action of command.
+ ///
+ public string Click { get; set; } = default!;
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/DefaultEditFrameButton.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/DefaultEditFrameButton.cs
new file mode 100644
index 0000000..d8b1fc5
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/DefaultEditFrameButton.cs
@@ -0,0 +1,84 @@
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers.Model;
+
+///
+/// This class contains a set of default edit frame buttons.
+///
+public static class DefaultEditFrameButton
+{
+ ///
+ /// Gets edit layout button.
+ ///
+ public static WebEditButton EditLayout => new()
+ {
+ Header = "Edit Layout",
+ Icon = "/~/icon/Office/16x16/document_selection.png",
+ Click = "webedit:openexperienceeditor",
+ Tooltip = "Open the item for editing",
+ };
+
+ ///
+ /// Gets delete button.
+ ///
+ public static WebEditButton Delete => new()
+ {
+ Header = "Delete Link",
+ Icon = "/~/icon/Office/16x16/delete.png",
+ Click = "webedit:delete",
+ Tooltip = "Delete the item",
+ };
+
+ ///
+ /// Gets move up button.
+ ///
+ public static WebEditButton MoveUp => new()
+ {
+ Header = "Move Up",
+ Icon = "/~/icon/Office/16x16/navigate_up.png",
+ Click = "item:moveup",
+ Tooltip = "Move the item up",
+ };
+
+ ///
+ /// Gets move down button.
+ ///
+ public static WebEditButton MoveDown => new()
+ {
+ Header = "Move Down",
+ Icon = "/~/icon/Office/16x16/navigate_down.png",
+ Click = "item:movedown",
+ Tooltip = "Move the item down",
+ };
+
+ ///
+ /// Gets move first button.
+ ///
+ public static WebEditButton MoveFirst => new()
+ {
+ Header = "Move First",
+ Icon = "/~/icon/Office/16x16/navigate_up2.png",
+ Click = "item:movefirst",
+ Tooltip = "Move the item first",
+ };
+
+ ///
+ /// Gets move last button.
+ ///
+ public static WebEditButton MoveLast => new()
+ {
+ Header = "Move Last",
+ Icon = "/~/icon/Office/16x16/navigate_down2.png",
+ Click = "item:movelast",
+ Tooltip = "Move the item last",
+ };
+
+ ///
+ /// Gets insert button.
+ ///
+ public static WebEditButton Insert => new()
+ {
+ Header = "Insert New",
+ Icon = "/~/icon/Office/16x16/insert_from_template.png",
+ Click = "webedit:new",
+ Tooltip = "Insert a new item",
+ };
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/DefaultEditFrameButtonIds.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/DefaultEditFrameButtonIds.cs
new file mode 100644
index 0000000..38e91a3
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/DefaultEditFrameButtonIds.cs
@@ -0,0 +1,12 @@
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers.Model;
+
+///
+/// Various constants relevant to the Edit Frame.
+///
+public static class DefaultEditFrameButtonIds
+{
+ ///
+ /// Gets the ID of Edit item (/sitecore/content/Applications/WebEdit/Edit Frame Buttons/Default/Edit).
+ ///
+ public static readonly string Edit = "{70C4EED5-D4CD-4D7D-9763-80C42504F5E7}";
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/DividerEditButton.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/DividerEditButton.cs
new file mode 100644
index 0000000..7271b99
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/DividerEditButton.cs
@@ -0,0 +1,13 @@
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers.Model;
+
+///
+/// This class represents a button-separator for edit frame.
+///
+public class DividerEditButton : EditButtonBase
+{
+ ///
+ public override string Header => "Separator";
+
+ ///
+ public override string Icon => string.Empty;
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/EditButtonBase.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/EditButtonBase.cs
new file mode 100644
index 0000000..095c4d5
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/EditButtonBase.cs
@@ -0,0 +1,22 @@
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers.Model;
+
+///
+/// This class contains base fields for edit buttons.
+///
+public abstract class EditButtonBase
+{
+ ///
+ /// Gets or sets the title of the button.
+ ///
+ public virtual string? Header { get; set; }
+
+ ///
+ /// Gets or sets the icon path.
+ ///
+ public virtual string? Icon { get; set; }
+
+ ///
+ /// Gets or sets the tooltip of the button.
+ ///
+ public virtual string? Tooltip { get; set; }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/EditFrameDataSource.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/EditFrameDataSource.cs
new file mode 100644
index 0000000..26a634a
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/EditFrameDataSource.cs
@@ -0,0 +1,22 @@
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers.Model;
+
+///
+/// This class represents the data source for Edit Frame.
+///
+public class EditFrameDataSource
+{
+ ///
+ /// Gets or sets the item ID.
+ ///
+ public string? ItemId { get; set; }
+
+ ///
+ /// Gets or sets the database name.
+ ///
+ public string? DatabaseName { get; set; }
+
+ ///
+ /// Gets or sets the language.
+ ///
+ public string? Language { get; set; }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/FieldEditButton.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/FieldEditButton.cs
new file mode 100644
index 0000000..fa56e99
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/FieldEditButton.cs
@@ -0,0 +1,12 @@
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers.Model;
+
+///
+/// This class represents the edit button which allows manipulation with defined fields.
+///
+public class FieldEditButton : EditButtonBase
+{
+ ///
+ /// Gets the collection of the field names.
+ ///
+ public IEnumerable Fields { get; init; } = [];
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/WebEditButton.cs b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/WebEditButton.cs
new file mode 100644
index 0000000..3211ad9
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.ExperienceEditor/TagHelpers/Model/WebEditButton.cs
@@ -0,0 +1,22 @@
+namespace Sitecore.AspNetCore.SDK.ExperienceEditor.TagHelpers.Model;
+
+///
+/// This class represents web edit button.
+///
+public class WebEditButton : EditButtonBase
+{
+ ///
+ /// Gets or sets the click action of the button.
+ ///
+ public string? Click { get; set; }
+
+ ///
+ /// Gets or sets the type of button.
+ ///
+ public string? Type { get; set; }
+
+ ///
+ /// Gets or sets the additional parameters of the button.
+ ///
+ public IDictionary? Parameters { get; set; }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.GraphQL/Client/Models/SitecoreGraphQLClientOptions.cs b/src/Sitecore.AspNetCore.SDK.GraphQL/Client/Models/SitecoreGraphQLClientOptions.cs
new file mode 100644
index 0000000..da87e38
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.GraphQL/Client/Models/SitecoreGraphQLClientOptions.cs
@@ -0,0 +1,26 @@
+using GraphQL.Client.Abstractions.Websocket;
+using GraphQL.Client.Http;
+using GraphQL.Client.Serializer.SystemTextJson;
+
+namespace Sitecore.AspNetCore.SDK.GraphQL.Client.Models;
+
+///
+/// GraphQL Client options needed for Preview or Edge schemas.
+///
+public class SitecoreGraphQlClientOptions : GraphQLHttpClientOptions
+{
+ ///
+ /// Gets or sets ApiKey.
+ ///
+ public string? ApiKey { get; set; }
+
+ ///
+ /// Gets or sets Default site name, used by middlewares which use GraphQl client.
+ ///
+ public string? DefaultSiteName { get; set; }
+
+ ///
+ /// Gets or sets GraphQLJsonSerializer, which could be SystemTextJsonSerializer or NewtonsoftJsonSerializer, SystemTextJsonSerializer by default.
+ ///
+ public IGraphQLWebsocketJsonSerializer GraphQlJsonSerializer { get; set; } = new SystemTextJsonSerializer();
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.GraphQL/Exceptions/InvalidGraphQLConfigurationException.cs b/src/Sitecore.AspNetCore.SDK.GraphQL/Exceptions/InvalidGraphQLConfigurationException.cs
new file mode 100644
index 0000000..0cd0d78
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.GraphQL/Exceptions/InvalidGraphQLConfigurationException.cs
@@ -0,0 +1,33 @@
+namespace Sitecore.AspNetCore.SDK.GraphQL.Exceptions;
+
+///
+/// Details an exception that may occur during GraphQl configuration.
+///
+public class InvalidGraphQlConfigurationException : Exception
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public InvalidGraphQlConfigurationException()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ public InvalidGraphQlConfigurationException(string message)
+ : base(message)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ /// The inner exception to be wrapped.
+ public InvalidGraphQlConfigurationException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.GraphQL/Extensions/GraphQlConfigurationExtensions.cs b/src/Sitecore.AspNetCore.SDK.GraphQL/Extensions/GraphQlConfigurationExtensions.cs
new file mode 100644
index 0000000..31923da
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.GraphQL/Extensions/GraphQlConfigurationExtensions.cs
@@ -0,0 +1,57 @@
+using GraphQL.Client.Abstractions;
+using GraphQL.Client.Http;
+using Microsoft.Extensions.DependencyInjection;
+using Sitecore.AspNetCore.SDK.GraphQL.Client.Models;
+using Sitecore.AspNetCore.SDK.GraphQL.Exceptions;
+
+namespace Sitecore.AspNetCore.SDK.GraphQL.Extensions;
+
+///
+/// Sitemap configuration.
+///
+public static class GraphQlConfigurationExtensions
+{
+ ///
+ /// Configuration for GraphQLClient.
+ ///
+ /// The to add services to.
+ /// The configuration for GraphQL client.
+ /// The so that additional calls can be chained.
+ public static IServiceCollection AddGraphQlClient(this IServiceCollection services, Action configuration)
+ {
+ ArgumentNullException.ThrowIfNull(services);
+ ArgumentNullException.ThrowIfNull(configuration);
+
+ services.Configure(configuration);
+
+ SitecoreGraphQlClientOptions graphQlClientOptions = TryGetConfiguration(configuration);
+
+ services.AddSingleton(_ =>
+ {
+ GraphQLHttpClient graphQlHttpClient = new(graphQlClientOptions.EndPoint!, graphQlClientOptions.GraphQlJsonSerializer);
+
+ graphQlHttpClient.HttpClient.DefaultRequestHeaders.Add("sc_apikey", graphQlClientOptions.ApiKey);
+ return graphQlHttpClient;
+ });
+
+ return services;
+ }
+
+ private static SitecoreGraphQlClientOptions TryGetConfiguration(Action configuration)
+ {
+ SitecoreGraphQlClientOptions graphQlClientOptions = new();
+ configuration.Invoke(graphQlClientOptions);
+
+ if (string.IsNullOrWhiteSpace(graphQlClientOptions.ApiKey))
+ {
+ throw new InvalidGraphQlConfigurationException("Empty ApiKey, provided in GraphQLClientOptions.");
+ }
+
+ if (graphQlClientOptions.EndPoint == null)
+ {
+ throw new InvalidGraphQlConfigurationException("Empty EndPoint, provided in GraphQLClientOptions.");
+ }
+
+ return graphQlClientOptions;
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.GraphQL/Sitecore.AspNetCore.SDK.GraphQL.csproj b/src/Sitecore.AspNetCore.SDK.GraphQL/Sitecore.AspNetCore.SDK.GraphQL.csproj
new file mode 100644
index 0000000..1270519
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.GraphQL/Sitecore.AspNetCore.SDK.GraphQL.csproj
@@ -0,0 +1,14 @@
+
+
+
+ Sitecore GQL
+ .NET Client for Sitecore GQL
+
+
+
+
+
+
+
+
+
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/HttpLayoutRequestHandlerOptions.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/HttpLayoutRequestHandlerOptions.cs
new file mode 100644
index 0000000..fa1d46b
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/HttpLayoutRequestHandlerOptions.cs
@@ -0,0 +1,14 @@
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Request;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Request.Handlers;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Configuration;
+
+///
+/// Options to control the for the Sitecore layout service.
+///
+public class HttpLayoutRequestHandlerOptions : IMapRequest
+{
+ ///
+ public List> RequestMap { get; init; } = [];
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutClientBuilder.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutClientBuilder.cs
new file mode 100644
index 0000000..7c07ee6
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutClientBuilder.cs
@@ -0,0 +1,16 @@
+using Microsoft.Extensions.DependencyInjection;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Configuration;
+
+///
+///
+/// Initializes a new instance of the class.
+///
+/// The initial .
+public class SitecoreLayoutClientBuilder(IServiceCollection services)
+ : ISitecoreLayoutClientBuilder
+{
+ ///
+ public IServiceCollection Services { get; protected set; } = services ?? throw new ArgumentNullException(nameof(services));
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutClientOptions.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutClientOptions.cs
new file mode 100644
index 0000000..18cf2a2
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutClientOptions.cs
@@ -0,0 +1,19 @@
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Configuration;
+
+///
+/// Options to control the Sitecore .
+///
+public class SitecoreLayoutClientOptions
+{
+ ///
+ /// Gets the registry of Sitecore layout service request handlers.
+ ///
+ public Dictionary> HandlerRegistry { get; init; } = [];
+
+ ///
+ /// Gets or sets the default handler name for requests.
+ ///
+ public string? DefaultHandler { get; set; }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutRequestHandlerBuilder.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutRequestHandlerBuilder.cs
new file mode 100644
index 0000000..e6b59b7
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutRequestHandlerBuilder.cs
@@ -0,0 +1,32 @@
+using Microsoft.Extensions.DependencyInjection;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Configuration;
+
+///
+///
+/// Initializes a new instance of the class.
+///
+public class SitecoreLayoutRequestHandlerBuilder : ILayoutRequestHandlerBuilder
+ where THandler : ILayoutRequestHandler
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The name of the handler being configured.
+ /// The initial .
+ public SitecoreLayoutRequestHandlerBuilder(string handlerName, IServiceCollection services)
+ {
+ ArgumentException.ThrowIfNullOrWhiteSpace(handlerName);
+ ArgumentNullException.ThrowIfNull(services);
+
+ Services = services;
+ HandlerName = handlerName;
+ }
+
+ ///
+ public IServiceCollection Services { get; }
+
+ ///
+ public string HandlerName { get; }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutRequestOptions.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutRequestOptions.cs
new file mode 100644
index 0000000..2c1661d
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutRequestOptions.cs
@@ -0,0 +1,20 @@
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Request;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Configuration;
+
+///
+/// Options to control the .
+///
+public class SitecoreLayoutRequestOptions
+{
+ private SitecoreLayoutRequest _requestDefaults = [];
+
+ ///
+ /// Gets or sets the default parameters for all requests made using the .
+ ///
+ public SitecoreLayoutRequest RequestDefaults
+ {
+ get => _requestDefaults;
+ set => _requestDefaults = value ?? throw new ArgumentNullException(nameof(value));
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutServiceMarkerService.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutServiceMarkerService.cs
new file mode 100644
index 0000000..69643fb
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Configuration/SitecoreLayoutServiceMarkerService.cs
@@ -0,0 +1,6 @@
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Configuration;
+
+///
+/// Marker service used to identify when Sitecore layout service services have been registered.
+///
+internal class SitecoreLayoutServiceMarkerService;
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/DefaultLayoutClient.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/DefaultLayoutClient.cs
new file mode 100644
index 0000000..e3da3ad
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/DefaultLayoutClient.cs
@@ -0,0 +1,113 @@
+using System.Text.Json;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Configuration;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Properties;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Request;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Response;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client;
+
+///
+///
+/// Initializes a new instance of the class.
+///
+/// The services used for handler resolution.
+/// The for this instance.
+/// An to access specific options for the default client request.
+/// The to use for logging.
+public class DefaultLayoutClient(
+ IServiceProvider services,
+ IOptions layoutClientOptions,
+ IOptionsSnapshot layoutRequestOptions,
+ ILogger logger)
+ : ISitecoreLayoutClient
+{
+ private readonly IServiceProvider _services = services ?? throw new ArgumentNullException(nameof(services));
+ private readonly IOptions _layoutClientOptions = layoutClientOptions ?? throw new ArgumentNullException(nameof(layoutClientOptions));
+ private readonly IOptionsSnapshot _layoutRequestOptions = layoutRequestOptions ?? throw new ArgumentNullException(nameof(layoutRequestOptions));
+ private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger));
+
+ ///
+ public async Task Request(SitecoreLayoutRequest request)
+ {
+ ArgumentNullException.ThrowIfNull(request);
+ return await Request(request, string.Empty).ConfigureAwait(false);
+ }
+
+ ///
+ public async Task Request(SitecoreLayoutRequest request, string handlerName)
+ {
+ ArgumentNullException.ThrowIfNull(request);
+
+ string? finalHandlerName = !string.IsNullOrWhiteSpace(handlerName) ? handlerName : _layoutClientOptions.Value.DefaultHandler;
+
+ if (string.IsNullOrWhiteSpace(finalHandlerName))
+ {
+ throw new ArgumentNullException(finalHandlerName, Resources.Exception_HandlerNameIsNull);
+ }
+
+ if (!_layoutClientOptions.Value.HandlerRegistry.TryGetValue(finalHandlerName, out Func? value))
+ {
+ throw new KeyNotFoundException(string.Format(Resources.Exception_HandlerRegistryKeyNotFound, finalHandlerName));
+ }
+
+ SitecoreLayoutRequestOptions mergedLayoutRequestOptions = MergeLayoutRequestOptions(finalHandlerName);
+
+ SitecoreLayoutRequest finalRequest = request.UpdateRequest(mergedLayoutRequestOptions.RequestDefaults);
+
+ if (_logger.IsEnabled(LogLevel.Trace))
+ {
+ string serializedRequest = JsonSerializer.Serialize(finalRequest);
+ _logger.LogTrace("Sitecore Layout Request {serializedRequest}", serializedRequest);
+ }
+
+ ILayoutRequestHandler handler = value.Invoke(_services);
+
+ return await handler.Request(finalRequest, finalHandlerName).ConfigureAwait(false);
+ }
+
+ private static bool AreEqual(SitecoreLayoutRequest request1, SitecoreLayoutRequest request2)
+ {
+ if (request1.Count != request2.Count)
+ {
+ return false;
+ }
+
+ ICollection dictionary1Keys = request1.Keys;
+ foreach (string key in dictionary1Keys)
+ {
+ if (!(request2.TryGetValue(key, out object? value) &&
+ request1[key] == value))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private SitecoreLayoutRequestOptions MergeLayoutRequestOptions(string handlerName)
+ {
+ SitecoreLayoutRequestOptions globalLayoutRequestOptions = _layoutRequestOptions.Value;
+ SitecoreLayoutRequestOptions handlerLayoutRequestOptions = _layoutRequestOptions.Get(handlerName);
+
+ if (AreEqual(globalLayoutRequestOptions.RequestDefaults, handlerLayoutRequestOptions.RequestDefaults))
+ {
+ return globalLayoutRequestOptions;
+ }
+
+ SitecoreLayoutRequest mergedRequestDefaults = globalLayoutRequestOptions.RequestDefaults;
+ SitecoreLayoutRequest handlerRequestDefaults = handlerLayoutRequestOptions.RequestDefaults;
+
+ foreach (KeyValuePair entry in handlerRequestDefaults)
+ {
+ mergedRequestDefaults[entry.Key] = handlerRequestDefaults[entry.Key];
+ }
+
+ globalLayoutRequestOptions.RequestDefaults = mergedRequestDefaults;
+
+ return globalLayoutRequestOptions;
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/CouldNotContactSitecoreLayoutServiceClientException.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/CouldNotContactSitecoreLayoutServiceClientException.cs
new file mode 100644
index 0000000..d1b5adc
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/CouldNotContactSitecoreLayoutServiceClientException.cs
@@ -0,0 +1,45 @@
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Properties;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Exceptions;
+
+///
+/// Details an exception that may occur when the Sitecore layout service cannot be contacted.
+///
+public class CouldNotContactSitecoreLayoutServiceClientException : SitecoreLayoutServiceClientException
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ public CouldNotContactSitecoreLayoutServiceClientException(string message)
+ : base(message)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ /// The inner exception to be wrapped.
+ public CouldNotContactSitecoreLayoutServiceClientException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public CouldNotContactSitecoreLayoutServiceClientException()
+ : base(Resources.Exception_CouldNotContactService)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The inner exception to be wrapped.
+ public CouldNotContactSitecoreLayoutServiceClientException(Exception innerException)
+ : this(Resources.Exception_CouldNotContactService, innerException)
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/FieldReaderException.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/FieldReaderException.cs
new file mode 100644
index 0000000..ea385cd
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/FieldReaderException.cs
@@ -0,0 +1,47 @@
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Properties;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Exceptions;
+
+///
+/// Details an exception that may occur when reading a Field.
+///
+public class FieldReaderException : Exception
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ public FieldReaderException(string message)
+ : base(message)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ /// The inner exception to be wrapped.
+ public FieldReaderException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The type attempting to be read.
+ public FieldReaderException(Type type)
+ : base(string.Format(Resources.Exception_ReadingField, type))
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The type attempting to be read.
+ /// The inner exception to be wrapped.
+ public FieldReaderException(Type type, Exception innerException)
+ : base(string.Format(Resources.Exception_ReadingField, type), innerException)
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/InvalidRequestSitecoreLayoutServiceClientException.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/InvalidRequestSitecoreLayoutServiceClientException.cs
new file mode 100644
index 0000000..4b62b45
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/InvalidRequestSitecoreLayoutServiceClientException.cs
@@ -0,0 +1,45 @@
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Properties;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Exceptions;
+
+///
+/// Details an exception that may occur when the Sitecore layout service is invoked with an invalid request.
+///
+public class InvalidRequestSitecoreLayoutServiceClientException : SitecoreLayoutServiceClientException
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ public InvalidRequestSitecoreLayoutServiceClientException(string message)
+ : base(message)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ /// The inner exception to be wrapped.
+ public InvalidRequestSitecoreLayoutServiceClientException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public InvalidRequestSitecoreLayoutServiceClientException()
+ : base(Resources.Exception_InvalidRequestError)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The inner exception to be wrapped.
+ public InvalidRequestSitecoreLayoutServiceClientException(Exception innerException)
+ : this(Resources.Exception_InvalidRequestError, innerException)
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/InvalidResponseSitecoreLayoutServiceClientException.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/InvalidResponseSitecoreLayoutServiceClientException.cs
new file mode 100644
index 0000000..15c8ea9
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/InvalidResponseSitecoreLayoutServiceClientException.cs
@@ -0,0 +1,45 @@
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Properties;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Exceptions;
+
+///
+/// Details an exception that may occur when the Sitecore layout service returns an invalid response.
+///
+public class InvalidResponseSitecoreLayoutServiceClientException : SitecoreLayoutServiceClientException
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ public InvalidResponseSitecoreLayoutServiceClientException(string message)
+ : base(message)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ /// The inner exception to be wrapped.
+ public InvalidResponseSitecoreLayoutServiceClientException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public InvalidResponseSitecoreLayoutServiceClientException()
+ : base(Resources.Exception_InvalidResponseFormat)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The inner exception to be wrapped.
+ public InvalidResponseSitecoreLayoutServiceClientException(Exception innerException)
+ : this(Resources.Exception_InvalidResponseFormat, innerException)
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/ItemNotFoundSitecoreLayoutServiceClientException.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/ItemNotFoundSitecoreLayoutServiceClientException.cs
new file mode 100644
index 0000000..e362126
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/ItemNotFoundSitecoreLayoutServiceClientException.cs
@@ -0,0 +1,45 @@
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Properties;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Exceptions;
+
+///
+/// Details an exception that may occur when the Sitecore layout service returns a 'not found' (404) response.
+///
+public class ItemNotFoundSitecoreLayoutServiceClientException : SitecoreLayoutServiceClientException
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ public ItemNotFoundSitecoreLayoutServiceClientException(string message)
+ : base(message)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ /// The inner exception to be wrapped.
+ public ItemNotFoundSitecoreLayoutServiceClientException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public ItemNotFoundSitecoreLayoutServiceClientException()
+ : base(Resources.Exception_ItemNotFoundError)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The inner exception to be wrapped.
+ public ItemNotFoundSitecoreLayoutServiceClientException(Exception innerException)
+ : this(Resources.Exception_ItemNotFoundError, innerException)
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/SitecoreLayoutServiceClientException.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/SitecoreLayoutServiceClientException.cs
new file mode 100644
index 0000000..fea3333
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/SitecoreLayoutServiceClientException.cs
@@ -0,0 +1,45 @@
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Properties;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Exceptions;
+
+///
+/// Details an exception that may occur when communicating with the Sitecore layout service.
+///
+public class SitecoreLayoutServiceClientException : Exception
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ public SitecoreLayoutServiceClientException(string message)
+ : base(message)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ /// The inner exception to be wrapped.
+ public SitecoreLayoutServiceClientException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public SitecoreLayoutServiceClientException()
+ : this(Resources.Exception_GeneralServiceError)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The inner exception to be wrapped.
+ public SitecoreLayoutServiceClientException(Exception innerException)
+ : this(Resources.Exception_GeneralServiceError, innerException)
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/SitecoreLayoutServiceMessageConfigurationException.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/SitecoreLayoutServiceMessageConfigurationException.cs
new file mode 100644
index 0000000..3cdfba0
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/SitecoreLayoutServiceMessageConfigurationException.cs
@@ -0,0 +1,45 @@
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Properties;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Exceptions;
+
+///
+/// Details an exception that may occur when invalid configuration is applied to the message sent to the Sitecore layout service.
+///
+public class SitecoreLayoutServiceMessageConfigurationException : SitecoreLayoutServiceClientException
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ public SitecoreLayoutServiceMessageConfigurationException(string message)
+ : base(message)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ /// The inner exception to be wrapped.
+ public SitecoreLayoutServiceMessageConfigurationException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public SitecoreLayoutServiceMessageConfigurationException()
+ : base(Resources.Exception_MessageConfigurationError)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The inner exception to be wrapped.
+ public SitecoreLayoutServiceMessageConfigurationException(Exception innerException)
+ : this(Resources.Exception_MessageConfigurationError, innerException)
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/SitecoreLayoutServiceServerException.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/SitecoreLayoutServiceServerException.cs
new file mode 100644
index 0000000..64bd0f8
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Exceptions/SitecoreLayoutServiceServerException.cs
@@ -0,0 +1,45 @@
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Properties;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Exceptions;
+
+///
+/// Details an exception that may occur when the Sitecore layout service returns a server related error.
+///
+public class SitecoreLayoutServiceServerException : InvalidResponseSitecoreLayoutServiceClientException
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ public SitecoreLayoutServiceServerException(string message)
+ : base(message)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The exception message.
+ /// The inner exception to be wrapped.
+ public SitecoreLayoutServiceServerException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public SitecoreLayoutServiceServerException()
+ : base(Resources.Exception_LayoutServiceServerError)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The inner exception to be wrapped.
+ public SitecoreLayoutServiceServerException(Exception innerException)
+ : this(Resources.Exception_LayoutServiceServerError, innerException)
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/DictionaryExtensions.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/DictionaryExtensions.cs
new file mode 100644
index 0000000..5418d9e
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/DictionaryExtensions.cs
@@ -0,0 +1,20 @@
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions;
+
+///
+/// Extension methods to convert dictionary collection to string format.
+///
+internal static class DictionaryExtensions
+{
+ ///
+ /// Converts dictionary collection to string format.
+ ///
+ /// The key of the dictionary.
+ /// The value of the dictionary.
+ /// The dictionary being configured.
+ /// The configured .
+ public static string ToDebugString(this IDictionary dictionary)
+ {
+ ArgumentNullException.ThrowIfNull(dictionary);
+ return "{" + string.Join(",", dictionary.Select(kv => kv.Key + "=" + kv.Value).ToArray()) + "}";
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/JsonSerializerOptionsExtensions.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/JsonSerializerOptionsExtensions.cs
new file mode 100644
index 0000000..4671ed4
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/JsonSerializerOptionsExtensions.cs
@@ -0,0 +1,29 @@
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Serialization.Converter;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions;
+
+///
+/// Extension methods for .
+///
+public static class JsonSerializerOptionsExtensions
+{
+ ///
+ /// Adds the default Layout Service serialization settings to the provided .
+ ///
+ /// The to add the default settings to.
+ /// The modified with the default settings added.
+ public static JsonSerializerOptions AddLayoutServiceDefaults(this JsonSerializerOptions options)
+ {
+ options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
+ options.NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString;
+ options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault;
+ options.PropertyNameCaseInsensitive = true;
+ options.Converters.Add(new JsonStringEnumConverter());
+ options.Converters.Add(new FieldConverter());
+ options.Converters.Add(new PlaceholderFeatureConverter(new FieldParser()));
+
+ return options;
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/LayoutRequestHandlerBuilderExtensions.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/LayoutRequestHandlerBuilderExtensions.cs
new file mode 100644
index 0000000..79ee059
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/LayoutRequestHandlerBuilderExtensions.cs
@@ -0,0 +1,110 @@
+using System.Net.Http.Headers;
+using Microsoft.Extensions.DependencyInjection;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Configuration;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Request;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Request.Handlers;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions;
+
+///
+/// Extension methods to support configuration of Sitecore layout request handler services.
+///
+public static class LayoutRequestHandlerBuilderExtensions
+{
+ ///
+ /// Sets the current handler being built as the default handler for Sitecore layout service client requests.
+ ///
+ /// The type of handler being configured.
+ /// The builder being configured.
+ /// The configured .
+ public static ILayoutRequestHandlerBuilder AsDefaultHandler(
+ this ILayoutRequestHandlerBuilder builder)
+ where THandler : ILayoutRequestHandler
+ {
+ ArgumentNullException.ThrowIfNull(builder);
+
+ builder.Services.Configure(options => options.DefaultHandler = builder.HandlerName);
+
+ return builder;
+ }
+
+ ///
+ /// Registers the default Sitecore layout service request options for the given handler.
+ ///
+ /// The type of handler being configured.
+ /// The being configured.
+ /// The request options configuration.
+ /// The configured .
+ public static ILayoutRequestHandlerBuilder WithRequestOptions(
+ this ILayoutRequestHandlerBuilder builder,
+ Action configureRequest)
+ where THandler : ILayoutRequestHandler
+ {
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(configureRequest);
+
+ builder.Services.Configure(builder.HandlerName, options => configureRequest(options.RequestDefaults));
+
+ return builder;
+ }
+
+ ///
+ /// Registers a configuration action as named for the given handler.
+ ///
+ /// The to configure.
+ /// The configuration based on .
+ /// The configured .
+ public static ILayoutRequestHandlerBuilder MapFromRequest(
+ this ILayoutRequestHandlerBuilder builder, Action configureHttpRequestMessage)
+ {
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(configureHttpRequestMessage);
+
+ builder.Services.Configure(builder.HandlerName, options => options.RequestMap.Add(configureHttpRequestMessage));
+
+ return builder;
+ }
+
+ ///
+ /// Adds default configuration for the HTTP request message.
+ ///
+ /// The to configure.
+ /// The list of headers which should not be validated.
+ /// The so that additional calls can be chained.
+ public static ILayoutRequestHandlerBuilder ConfigureRequest(
+ this ILayoutRequestHandlerBuilder httpHandlerBuilder, string[] nonValidatedHeaders)
+ {
+ ArgumentNullException.ThrowIfNull(httpHandlerBuilder);
+ ArgumentNullException.ThrowIfNull(nonValidatedHeaders);
+
+ httpHandlerBuilder.MapFromRequest((request, message) =>
+ {
+ message.RequestUri = message.RequestUri != null
+ ? request.BuildDefaultSitecoreLayoutRequestUri(message.RequestUri)
+ : null;
+
+ if (request.TryReadValue(RequestKeys.AuthHeaderKey, out string? headerValue))
+ {
+ message.Headers.Authorization = new AuthenticationHeaderValue("Bearer", headerValue);
+ }
+
+ if (request.TryGetHeadersCollection(out Dictionary? headers))
+ {
+ foreach (KeyValuePair h in headers ?? [])
+ {
+ if (nonValidatedHeaders.Contains(h.Key))
+ {
+ message.Headers.TryAddWithoutValidation(h.Key, h.Value);
+ }
+ else
+ {
+ message.Headers.Add(h.Key, h.Value);
+ }
+ }
+ }
+ });
+
+ return httpHandlerBuilder;
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/ServiceCollectionExtensions.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/ServiceCollectionExtensions.cs
new file mode 100644
index 0000000..8fb38ab
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/ServiceCollectionExtensions.cs
@@ -0,0 +1,50 @@
+using Microsoft.Extensions.DependencyInjection;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Configuration;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Serialization;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions;
+
+///
+/// Extension methods to support Microsoft.Extensions.DependencyInjection.
+///
+public static class ServiceCollectionExtensions
+{
+ ///
+ /// Adds the services required to support the Sitecore layout service to the given .
+ ///
+ /// The to add services to.
+ /// >An action to configure the .
+ /// An so that Sitecore layout services may be configured further.
+ public static ISitecoreLayoutClientBuilder AddSitecoreLayoutService(
+ this IServiceCollection services,
+ Action? options = null)
+ {
+ ArgumentNullException.ThrowIfNull(services);
+
+ // Only register services if marker interface is missing
+ if (services.All(s => s.ServiceType != typeof(SitecoreLayoutServiceMarkerService)))
+ {
+ services.AddTransient(
+ sp =>
+ {
+ using IServiceScope scope = sp.CreateScope();
+ return ActivatorUtilities.CreateInstance(scope.ServiceProvider, sp);
+ });
+
+ SetSerializer(services);
+ }
+
+ if (options != null)
+ {
+ services.Configure(options);
+ }
+
+ return new SitecoreLayoutClientBuilder(services);
+ }
+
+ private static void SetSerializer(IServiceCollection services)
+ {
+ services.AddSingleton(new JsonLayoutServiceSerializer());
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/SitecoreLayoutClientBuilderExtensions.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/SitecoreLayoutClientBuilderExtensions.cs
new file mode 100644
index 0000000..7aef363
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/SitecoreLayoutClientBuilderExtensions.cs
@@ -0,0 +1,313 @@
+using System.Text.Json.Serialization;
+using GraphQL.Client.Abstractions;
+using GraphQL.Client.Http;
+using GraphQL.Client.Serializer.SystemTextJson;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+using Microsoft.Extensions.Logging;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Configuration;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Properties;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Request;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Request.Handlers;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Request.Handlers.GraphQL;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Serialization;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Serialization.Converter;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions;
+
+///
+/// Extension methods to support configuration of layout service services.
+///
+public static class SitecoreLayoutClientBuilderExtensions
+{
+ ///
+ /// Registers a handler of type to handle requests.
+ ///
+ /// The type of service to be registered for this .
+ /// The being configured.
+ /// The name used to identify the handler.
+ /// Optional factory to control the instantiation of the client.
+ /// The so that additional calls can be chained.
+ public static ILayoutRequestHandlerBuilder AddHandler(
+ this ISitecoreLayoutClientBuilder builder,
+ string name,
+ Func? factory = null)
+ where THandler : ILayoutRequestHandler
+ {
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentException.ThrowIfNullOrWhiteSpace(name);
+
+ Type handlerType = typeof(THandler);
+ if (handlerType.IsInterface)
+ {
+ throw new ArgumentException(string.Format(Resources.Exception_RegisterTypesOfService, typeof(THandler)));
+ }
+
+ if (handlerType.IsAbstract && factory == null)
+ {
+ throw new ArgumentException(Resources.Exception_AbstractRegistrationsMustProvideFactory);
+ }
+
+ factory ??= sp => ActivatorUtilities.CreateInstance(sp);
+
+ builder.Services.Configure(options =>
+ {
+ options.HandlerRegistry[name] = sp =>
+ {
+ using IServiceScope scope = sp.CreateScope();
+ return factory(scope.ServiceProvider);
+ };
+ });
+
+ return new SitecoreLayoutRequestHandlerBuilder(name, builder.Services);
+ }
+
+ ///
+ /// Registers a graphQl handler to handle requests.
+ ///
+ /// The being configured.
+ /// The name used to identify the handler.
+ /// The siteName used to identify the handler.
+ /// The apiKey to access graphQl endpoint.
+ /// GraphQl endpoint uri.
+ /// Default language for GraphQl requests.
+ /// The so that additional calls can be chained.
+ public static ILayoutRequestHandlerBuilder AddGraphQlHandler(
+ this ISitecoreLayoutClientBuilder builder,
+ string name,
+ string siteName,
+ string apiKey,
+ Uri uri,
+ string defaultLanguage = "en")
+ {
+ ArgumentNullException.ThrowIfNull(name);
+ ArgumentNullException.ThrowIfNull(siteName);
+ ArgumentNullException.ThrowIfNull(apiKey);
+ ArgumentNullException.ThrowIfNull(uri);
+
+ GraphQLHttpClient client = new(uri, new SystemTextJsonSerializer());
+ client.HttpClient.DefaultRequestHeaders.Add("sc_apikey", apiKey);
+
+ builder.WithDefaultRequestOptions(request =>
+ {
+ request
+ .SiteName(siteName)
+ .ApiKey(apiKey);
+ if (!request.ContainsKey(RequestKeys.Language))
+ {
+ request.Language(defaultLanguage);
+ }
+ });
+ return builder.AddHandler(name, (sp)
+ => ActivatorUtilities.CreateInstance(
+ sp, client, sp.GetRequiredService(), sp.GetRequiredService>()));
+ }
+
+ ///
+ /// Registers a graphQl handler to handle requests, it uses already configured GraphQL client.
+ ///
+ /// The being configured.
+ /// The name used to identify the handler.
+ /// The siteName used to identify the handler.
+ /// Default language for GraphQl requests.
+ /// The so that additional calls can be chained.
+ public static ILayoutRequestHandlerBuilder AddGraphQlHandler(
+ this ISitecoreLayoutClientBuilder builder,
+ string name,
+ string siteName,
+ string defaultLanguage = "en")
+ {
+ ArgumentNullException.ThrowIfNull(name);
+ ArgumentNullException.ThrowIfNull(siteName);
+
+ builder.WithDefaultRequestOptions(request =>
+ {
+ request
+ .SiteName(siteName);
+ if (!request.ContainsKey(RequestKeys.Language))
+ {
+ request.Language(defaultLanguage);
+ }
+ });
+ return builder.AddHandler(name, sp
+ => ActivatorUtilities.CreateInstance(
+ sp, sp.GetRequiredService(), sp.GetRequiredService(), sp.GetRequiredService>()));
+ }
+
+ ///
+ /// Registers the default layout service request options for all handlers.
+ ///
+ /// The being configured.
+ /// The request options configuration.
+ /// The configured .
+ public static ISitecoreLayoutClientBuilder WithDefaultRequestOptions(this ISitecoreLayoutClientBuilder builder, Action configureRequest)
+ {
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(configureRequest);
+
+ builder.Services.ConfigureAll(options => configureRequest(options.RequestDefaults));
+
+ return builder;
+ }
+
+ ///
+ /// Configures System.Text.Json specific features such as input and output formatters.
+ ///
+ /// The being configured.
+ /// The so that additional calls can be chained.
+ public static ISitecoreLayoutClientBuilder AddSystemTextJson(this ISitecoreLayoutClientBuilder builder)
+ {
+ ServiceDescriptor descriptor = new(typeof(ISitecoreLayoutSerializer), typeof(JsonLayoutServiceSerializer), ServiceLifetime.Singleton);
+ builder.Services.Replace(descriptor);
+
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton();
+
+ return builder;
+ }
+
+ ///
+ /// Registers a HTTP request handler for the Sitecore layout service client.
+ ///
+ /// The to configure.
+ /// The name of the request handler being registered.
+ /// A function to resolve the to be used. Be aware, that the underlying associated to the HttpClient will be reused across multiple sessions.
+ /// To prevent data, leaking among sessions, make sure Cookies are not cached. See for reference https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1#cookies .
+ /// The so that additional calls can be chained.
+ public static ILayoutRequestHandlerBuilder AddHttpHandler(
+ this ISitecoreLayoutClientBuilder builder,
+ string handlerName,
+ Func resolveClient)
+ {
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(handlerName);
+ ArgumentNullException.ThrowIfNull(resolveClient);
+
+ ILayoutRequestHandlerBuilder httpHandlerBuilder = builder.AddHandler(handlerName, sp =>
+ {
+ HttpClient client = resolveClient(sp);
+ return ActivatorUtilities.CreateInstance(sp, client);
+ });
+
+ httpHandlerBuilder.ConfigureRequest([]);
+
+ return httpHandlerBuilder;
+ }
+
+ ///
+ /// Registers an HTTP request handler for the Sitecore layout service client.
+ ///
+ /// The to configure.
+ /// The name of the request handler being registered.
+ /// A function to resolve the to be used. Be aware, that the underlying associated to the HttpClient will be reused across multiple sessions.
+ /// To prevent data, leaking among sessions, make sure Cookies are not cached. See for reference https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1#cookies .
+ /// The list of headers which should not be validated.
+ /// The so that additional calls can be chained.
+ public static ILayoutRequestHandlerBuilder AddHttpHandler(
+ this ISitecoreLayoutClientBuilder builder,
+ string handlerName,
+ Func resolveClient,
+ string[] nonValidatedHeaders)
+ {
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(handlerName);
+ ArgumentNullException.ThrowIfNull(resolveClient);
+ ArgumentNullException.ThrowIfNull(nonValidatedHeaders);
+
+ ILayoutRequestHandlerBuilder httpHandlerBuilder = builder.AddHandler(handlerName, sp =>
+ {
+ HttpClient client = resolveClient(sp);
+ return ActivatorUtilities.CreateInstance(sp, client);
+ });
+
+ httpHandlerBuilder.ConfigureRequest(nonValidatedHeaders);
+
+ return httpHandlerBuilder;
+ }
+
+ ///
+ /// Registers an HTTP request handler for the Sitecore layout service client.
+ ///
+ /// The to configure.
+ /// The name of the request handler being registered.
+ /// An action to configure the .
+ /// The so that additional calls can be chained.
+ public static ILayoutRequestHandlerBuilder AddHttpHandler(
+ this ISitecoreLayoutClientBuilder builder,
+ string handlerName,
+ Action configure)
+ {
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(handlerName);
+ ArgumentNullException.ThrowIfNull(configure);
+
+ builder.Services.AddHttpClient(handlerName, configure);
+
+ return AddHttpHandler(builder, handlerName, sp => sp.GetRequiredService().CreateClient(handlerName));
+ }
+
+ ///
+ /// Registers an HTTP request handler for the Sitecore layout service client.
+ ///
+ /// The to configure.
+ /// The name of the request handler being registered.
+ /// An action to configure the .
+ /// The so that additional calls can be chained.
+ public static ILayoutRequestHandlerBuilder AddHttpHandler(
+ this ISitecoreLayoutClientBuilder builder,
+ string handlerName,
+ Action configure)
+ {
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(handlerName);
+ ArgumentNullException.ThrowIfNull(configure);
+
+ builder.Services.AddHttpClient(handlerName, configure).ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
+ {
+ // DO NOT REMOVE - this prevents from cookies being shared among private sessions.
+ UseCookies = false
+ });
+
+ return AddHttpHandler(builder, handlerName, sp => sp.GetRequiredService().CreateClient(handlerName));
+ }
+
+ ///
+ /// Registers an HTTP request handler for the Sitecore layout service client.
+ ///
+ /// The to configure.
+ /// The name of the request handler being registered.
+ /// The used for the .
+ /// The so that additional calls can be chained.
+ public static ILayoutRequestHandlerBuilder AddHttpHandler(
+ this ISitecoreLayoutClientBuilder builder,
+ string handlerName,
+ Uri uri)
+ {
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(handlerName);
+ ArgumentNullException.ThrowIfNull(uri);
+
+ return AddHttpHandler(builder, handlerName, client => client.BaseAddress = uri);
+ }
+
+ ///
+ /// Registers an HTTP request handler for the Sitecore layout service client.
+ ///
+ /// The to configure.
+ /// The name of the request handler being registered.
+ /// The used for the .
+ /// The so that additional calls can be chained.
+ public static ILayoutRequestHandlerBuilder AddHttpHandler(
+ this ISitecoreLayoutClientBuilder builder,
+ string handlerName,
+ string uri)
+ {
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(handlerName);
+ ArgumentNullException.ThrowIfNull(uri);
+
+ return AddHttpHandler(builder, handlerName, new Uri(uri));
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/SitecoreLayoutRequestExtensions.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/SitecoreLayoutRequestExtensions.cs
new file mode 100644
index 0000000..144a94d
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/SitecoreLayoutRequestExtensions.cs
@@ -0,0 +1,85 @@
+using System.Net;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Request;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions;
+
+///
+/// HTTP related extension methods for the .
+///
+internal static class SitecoreLayoutRequestExtensions
+{
+ private static readonly List DefaultSitecoreRequestKeys =
+ [
+ RequestKeys.SiteName,
+ RequestKeys.Path,
+ RequestKeys.Language,
+ RequestKeys.ApiKey,
+ RequestKeys.Mode,
+ RequestKeys.PreviewDate
+ ];
+
+ ///
+ /// Build a URI using the default Sitecore layout entries in the provided request.
+ ///
+ /// The request object.
+ /// The base URI used to compose the final URI.
+ /// A URI containing the base URI and the relevant entries in the request object added as query strings.
+ public static Uri BuildDefaultSitecoreLayoutRequestUri(this SitecoreLayoutRequest request, Uri baseUri)
+ {
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentNullException.ThrowIfNull(baseUri);
+
+ return request.BuildUri(baseUri, DefaultSitecoreRequestKeys);
+ }
+
+ ///
+ /// Build a URI using the default Sitecore layout entries in the provided request.
+ ///
+ /// The request object.
+ /// The base URI used to compose the final URI.
+ /// The additional URI query parameters to get from the request.
+ /// A URI containing the base URI and the relevant entries in the request object added as query strings.
+ public static Uri BuildDefaultSitecoreLayoutRequestUri(this SitecoreLayoutRequest request, Uri baseUri, IEnumerable additionalQueryParameters)
+ {
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentNullException.ThrowIfNull(baseUri);
+ ArgumentNullException.ThrowIfNull(additionalQueryParameters);
+
+ List defaultKeys = [.. DefaultSitecoreRequestKeys];
+ defaultKeys.AddRange(additionalQueryParameters);
+
+ return request.BuildUri(baseUri, defaultKeys);
+ }
+
+ ///
+ /// Build a URI using all the entries in the provided request.
+ ///
+ /// The request object.
+ /// The base URI used to compose the final URL.
+ /// The URI query parameters to get from request.
+ /// A URI containing the base URI and all the valid entries in the request object added as query strings.
+ public static Uri BuildUri(this SitecoreLayoutRequest request, Uri baseUri, IEnumerable queryParameters)
+ {
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentNullException.ThrowIfNull(baseUri);
+ ArgumentNullException.ThrowIfNull(queryParameters);
+
+ List> entries = request.Where(entry => queryParameters.Contains(entry.Key)).ToList();
+ IEnumerable> validQueryParts = entries.Where(entry => entry.Value is string && !string.IsNullOrWhiteSpace(entry.Value.ToString()))!;
+ string[] queryParts = validQueryParts.Select(kvp => $"{WebUtility.UrlEncode(kvp.Key)}={WebUtility.UrlEncode(kvp.Value.ToString())}").ToArray();
+
+ if (queryParts.Length == 0)
+ {
+ return baseUri;
+ }
+
+ string queryString = $"?{string.Join("&", queryParts)}";
+
+ UriBuilder builder = new(baseUri)
+ {
+ Query = queryString
+ };
+
+ return builder.Uri;
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/ILayoutRequestHandler.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/ILayoutRequestHandler.cs
new file mode 100644
index 0000000..0e78317
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/ILayoutRequestHandler.cs
@@ -0,0 +1,18 @@
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Request;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Response;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces;
+
+///
+/// Supports making requests to the Sitecore layout service.
+///
+public interface ILayoutRequestHandler
+{
+ ///
+ /// Handles a request to the Sitecore layout service using the specified handler.
+ ///
+ /// The request details.
+ /// The name of the request handler to use to handle the request.
+ /// The response of the request.
+ Task Request(SitecoreLayoutRequest request, string handlerName);
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/ILayoutRequestHandlerBuilder.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/ILayoutRequestHandlerBuilder.cs
new file mode 100644
index 0000000..ad8a18c
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/ILayoutRequestHandlerBuilder.cs
@@ -0,0 +1,21 @@
+using Microsoft.Extensions.DependencyInjection;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces;
+
+///
+/// Contract for configuring named Sitecore layout service request handlers.
+///
+/// The type of handler being configured.
+public interface ILayoutRequestHandlerBuilder
+ where THandler : ILayoutRequestHandler
+{
+ ///
+ /// Gets the where Sitecore layout services are configured.
+ ///
+ IServiceCollection Services { get; }
+
+ ///
+ /// Gets the name of the handler being configured.
+ ///
+ string HandlerName { get; }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/IMapRequest.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/IMapRequest.cs
new file mode 100644
index 0000000..89f8898
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/IMapRequest.cs
@@ -0,0 +1,16 @@
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Request;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces;
+
+///
+/// Contract for mapping entries to an object of the given type.
+///
+/// The type the request is mapped to.
+public interface IMapRequest
+ where T : class
+{
+ ///
+ /// Gets the list of mappings from a to T.
+ ///
+ List> RequestMap { get; init; }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/ISitecoreLayoutClient.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/ISitecoreLayoutClient.cs
new file mode 100644
index 0000000..8f4e282
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/ISitecoreLayoutClient.cs
@@ -0,0 +1,17 @@
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Request;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Response;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces;
+
+///
+/// Supports making requests to the Sitecore layout service.
+///
+public interface ISitecoreLayoutClient : ILayoutRequestHandler
+{
+ ///
+ /// Invokes a request to the Sitecore layout service using the default handler name.
+ ///
+ /// The request details.
+ /// The response of the request.
+ Task Request(SitecoreLayoutRequest request);
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/ISitecoreLayoutClientBuilder.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/ISitecoreLayoutClientBuilder.cs
new file mode 100644
index 0000000..1d5765c
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Interfaces/ISitecoreLayoutClientBuilder.cs
@@ -0,0 +1,14 @@
+using Microsoft.Extensions.DependencyInjection;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces;
+
+///
+/// Contract for configuring Sitecore layout service clients.
+///
+public interface ISitecoreLayoutClientBuilder
+{
+ ///
+ /// Gets the where Sitecore layout services are configured.
+ ///
+ IServiceCollection Services { get; }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/LayoutServiceConstants.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/LayoutServiceConstants.cs
new file mode 100644
index 0000000..eb73e0b
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/LayoutServiceConstants.cs
@@ -0,0 +1,45 @@
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client;
+
+///
+/// Constants of the Layout Service Client.
+///
+[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Multi layered constants for easy use.")]
+public static class LayoutServiceClientConstants
+{
+ ///
+ /// Constants relevant to Sitecore layout service response chromes.
+ ///
+ public static class SitecoreChromes
+ {
+ ///
+ /// The name of the chrome type attribute.
+ ///
+ public const string ChromeTypeName = "type";
+
+ ///
+ /// The value of the chrome type attribute.
+ ///
+ public const string ChromeTypeValue = "text/sitecore";
+
+ ///
+ /// The default chrome HTML tag.
+ ///
+ public const string ChromeTag = "code";
+ }
+
+ ///
+ /// Constants relevant to Serialization.
+ ///
+ public static class Serialization
+ {
+ ///
+ /// The name of the SitecoreData property.
+ ///
+ public const string SitecoreDataPropertyName = "sitecore";
+
+ ///
+ /// The name of the Context property.
+ ///
+ public const string ContextPropertyName = "context";
+ }
+}
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Properties/Resources.Designer.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..a9ac577
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Properties/Resources.Designer.cs
@@ -0,0 +1,207 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Properties {
+ using System;
+
+
+ ///
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ ///
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ ///
+ /// Returns the cached ResourceManager instance used by this class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Sitecore.AspNetCore.SDK.LayoutService.Client.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Abstract registrations must provide a factory to resolve a layout service..
+ ///
+ internal static string Exception_AbstractRegistrationsMustProvideFactory {
+ get {
+ return ResourceManager.GetString("Exception_AbstractRegistrationsMustProvideFactory", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Could not contact the Sitecore layout service..
+ ///
+ internal static string Exception_CouldNotContactService {
+ get {
+ return ResourceManager.GetString("Exception_CouldNotContactService", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Could not convert field of type {0} into type {1}.
+ ///
+ internal static string Exception_CouldNotConvertFieldToType {
+ get {
+ return ResourceManager.GetString("Exception_CouldNotConvertFieldToType", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Could not find converter for {0}..
+ ///
+ internal static string Exception_CouldNotFindConverter {
+ get {
+ return ResourceManager.GetString("Exception_CouldNotFindConverter", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Expected an array or object when deserializing a {0}. Found {1}..
+ ///
+ internal static string Exception_DeserializationOfIncorrectToken {
+ get {
+ return ResourceManager.GetString("Exception_DeserializationOfIncorrectToken", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to An error occurred with the Sitecore layout service..
+ ///
+ internal static string Exception_GeneralServiceError {
+ get {
+ return ResourceManager.GetString("Exception_GeneralServiceError", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Handler name cannot be null..
+ ///
+ internal static string Exception_HandlerNameIsNull {
+ get {
+ return ResourceManager.GetString("Exception_HandlerNameIsNull", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to The {0} key cannot be found in the handler registry..
+ ///
+ internal static string Exception_HandlerRegistryKeyNotFound {
+ get {
+ return ResourceManager.GetString("Exception_HandlerRegistryKeyNotFound", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to An invalid request was sent to the Sitecore layout service..
+ ///
+ internal static string Exception_InvalidRequestError {
+ get {
+ return ResourceManager.GetString("Exception_InvalidRequestError", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to The Sitecore layout service returned a response in an invalid format..
+ ///
+ internal static string Exception_InvalidResponseFormat {
+ get {
+ return ResourceManager.GetString("Exception_InvalidResponseFormat", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to The Sitecore layout service returned an item not found response..
+ ///
+ internal static string Exception_ItemNotFoundError {
+ get {
+ return ResourceManager.GetString("Exception_ItemNotFoundError", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to The Sitecore layout service returned a server error..
+ ///
+ internal static string Exception_LayoutServiceServerError {
+ get {
+ return ResourceManager.GetString("Exception_LayoutServiceServerError", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to An error occurred while configuring the HTTP message..
+ ///
+ internal static string Exception_MessageConfigurationError {
+ get {
+ return ResourceManager.GetString("Exception_MessageConfigurationError", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to The Field could not be read as the type {0}.
+ ///
+ internal static string Exception_ReadingField {
+ get {
+ return ResourceManager.GetString("Exception_ReadingField", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Can only register implementations of {0} as layout services..
+ ///
+ internal static string Exception_RegisterTypesOfService {
+ get {
+ return ResourceManager.GetString("Exception_RegisterTypesOfService", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to HTTP Status Code.
+ ///
+ internal static string HttpStatusCode_KeyName {
+ get {
+ return ResourceManager.GetString("HttpStatusCode_KeyName", resourceCulture);
+ }
+ }
+ }
+}
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Properties/Resources.resx b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Properties/Resources.resx
new file mode 100644
index 0000000..c61eca9
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Properties/Resources.resx
@@ -0,0 +1,174 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ Abstract registrations must provide a factory to resolve a layout service.
+
+
+ Could not contact the Sitecore layout service.
+
+
+ Could not convert field of type {0} into type {1}
+ fromType,toType
+
+
+ Could not find converter for {0}.
+ objectType
+
+
+ Expected an array or object when deserializing a {0}. Found {1}.
+ expectedType, givenType
+
+
+ An error occurred with the Sitecore layout service.
+
+
+ Handler name cannot be null.
+
+
+ The {0} key cannot be found in the handler registry.
+ handlerName
+
+
+ An invalid request was sent to the Sitecore layout service.
+
+
+ The Sitecore layout service returned a response in an invalid format.
+
+
+ The Sitecore layout service returned an item not found response.
+
+
+ The Sitecore layout service returned a server error.
+
+
+ An error occurred while configuring the HTTP message.
+
+
+ The Field could not be read as the type {0}
+ type
+
+
+ Can only register implementations of {0} as layout services.
+ serviceType
+
+
+ HTTP Status Code
+
+
\ No newline at end of file
diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Request/Handlers/GraphQL/GraphQlLayoutServiceHandler.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Request/Handlers/GraphQL/GraphQlLayoutServiceHandler.cs
new file mode 100644
index 0000000..a3368c8
--- /dev/null
+++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Request/Handlers/GraphQL/GraphQlLayoutServiceHandler.cs
@@ -0,0 +1,100 @@
+using System.Text.Json;
+using GraphQL;
+using GraphQL.Client.Abstractions;
+using Microsoft.Extensions.Logging;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Exceptions;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Response;
+using Sitecore.AspNetCore.SDK.LayoutService.Client.Serialization;
+
+namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Request.Handlers.GraphQL;
+
+///
+///
+/// Initializes a new instance of the class.
+///
+/// The to use for logging.
+/// The graphQl client to handle response data.
+/// The serializer to handle response data.
+public class GraphQlLayoutServiceHandler(
+ IGraphQLClient client,
+ ISitecoreLayoutSerializer serializer,
+ ILogger logger)
+ : ILayoutRequestHandler
+{
+ private readonly ISitecoreLayoutSerializer _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
+ private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger));
+ private readonly IGraphQLClient _client = client ?? throw new ArgumentNullException(nameof(client));
+
+ ///
+ public async Task Request(SitecoreLayoutRequest request, string handlerName)
+ {
+ ArgumentNullException.ThrowIfNull(request);
+ ArgumentException.ThrowIfNullOrWhiteSpace(handlerName);
+
+ List errors = [];
+ SitecoreLayoutResponseContent? content = null;
+
+ string? requestLanguage = request.Language();
+
+ if (string.IsNullOrWhiteSpace(requestLanguage))
+ {
+ errors.Add(new ItemNotFoundSitecoreLayoutServiceClientException());
+ }
+ else
+ {
+ GraphQLRequest layoutRequest = new()
+ {
+ Query = @"
+ query LayoutQuery($path: String!, $language: String!, $site: String!) {
+ layout(routePath: $path, language: $language, site: $site) {
+ item {
+ rendered
+ }
+ }
+ }",
+ OperationName = "LayoutQuery",
+ Variables = new
+ {
+ path = request.Path(),
+ language = requestLanguage,
+ site = request.SiteName()
+ }
+ };
+
+ GraphQLResponse response = await _client.SendQueryAsync(layoutRequest).ConfigureAwait(false);
+ if (_logger.IsEnabled(LogLevel.Debug))
+ {
+ _logger.LogDebug("Layout Service GraphQL Response : {responseDataLayout}", response.Data.Layout);
+ }
+
+ // ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract - Data can be null due to bad implementation of dependency library
+ string? json = response.Data?.Layout?.Item?.Rendered.ToString();
+ if (json == null)
+ {
+ errors.Add(new ItemNotFoundSitecoreLayoutServiceClientException());
+ }
+ else
+ {
+ content = _serializer.Deserialize(json);
+ if (_logger.IsEnabled(LogLevel.Debug))
+ {
+ object? formattedDeserializeObject = JsonSerializer.Deserialize