-
Notifications
You must be signed in to change notification settings - Fork 824
Added docs on service registration options in 17.3 #7861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| --- | ||
| description: Learn how to configure Umbraco to run only the services required on each specific server in your setup. | ||
| --- | ||
|
|
||
| # Service Registration | ||
|
|
||
| Umbraco can be configured to run with different combinations of the backoffice, website, and Content Delivery API. This allows you to tailor each server in your infrastructure to its specific role, reducing attack surface and unnecessary processing. | ||
|
|
||
| ## Supported Configurations | ||
|
|
||
| By default, Umbraco registers all services: the backoffice, website rendering, and Content Delivery API. However, you can choose to run only the services you need. | ||
|
|
||
| The following configurations are supported: | ||
|
|
||
| | Configuration | Builder Methods | Use Case | | ||
| |---|---|---| | ||
| | Full (default) | `AddBackOffice()` + `AddWebsite()` + `AddDeliveryApi()` | Traditional Umbraco with all features enabled. | | ||
| | Website + Delivery API | `AddCore()` + `AddWebsite()` + `AddDeliveryApi()` | Front-end servers serving both rendered pages and headless content. | | ||
| | Website only | `AddCore()` + `AddWebsite()` | Front-end servers serving only rendered pages. | | ||
| | Delivery API only | `AddCore()` + `AddDeliveryApi()` | Pure headless API servers. | | ||
|
|
||
| The key distinction is between `AddBackOffice()` and `AddCore()`: | ||
|
|
||
| - **`AddBackOffice()`** registers everything needed for the Umbraco backoffice, including the Management API, backoffice identity, and all supporting services. | ||
| - **`AddCore()`** registers only the foundational Umbraco services β configuration, core services, web components, caching, and background jobs β without any backoffice-specific services. | ||
|
|
||
| `AddBackOffice()` calls `AddCore()` internally, so there is no need to call both. | ||
|
|
||
| {% hint style="info" %} | ||
| `AddCore()` is idempotent. If both `AddBackOffice()` and `AddCore()` are called, the core services are only registered once. | ||
| {% endhint %} | ||
|
|
||
| ## Full Umbraco (default) | ||
|
|
||
| The following is the standard configuration that includes the backoffice, website rendering, and Content Delivery API. | ||
|
|
||
| When you install a new Umbraco project, this is what you will see in the `Program.cs` file: | ||
|
|
||
| {% code title="Program.cs" %} | ||
| ```csharp | ||
| WebApplicationBuilder builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.CreateUmbracoBuilder() | ||
| .AddBackOffice() | ||
| .AddWebsite() | ||
| .AddDeliveryApi() | ||
| .AddComposers() | ||
| .Build(); | ||
|
|
||
| WebApplication app = builder.Build(); | ||
|
|
||
| await app.BootUmbracoAsync(); | ||
|
|
||
| app.UseUmbraco() | ||
| .WithMiddleware(u => | ||
| { | ||
| u.UseBackOffice(); | ||
| u.UseWebsite(); | ||
| }) | ||
| .WithEndpoints(u => | ||
| { | ||
| u.UseBackOfficeEndpoints(); | ||
| u.UseWebsiteEndpoints(); | ||
| }); | ||
|
|
||
| await app.RunAsync(); | ||
| ``` | ||
| {% endcode %} | ||
|
|
||
| ## Website + Delivery API (no backoffice) | ||
|
|
||
| The following configuration is useful for front-end servers in a load-balanced setup where a single backoffice instance is running. | ||
|
|
||
| The server can render pages and serve headless content, but the backoffice is not available. | ||
|
|
||
| {% code title="Program.cs" %} | ||
| ```csharp | ||
| WebApplicationBuilder builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.CreateUmbracoBuilder() | ||
| .AddCore() | ||
| .AddWebsite() | ||
| .AddDeliveryApi() | ||
| .AddComposers() | ||
| .Build(); | ||
|
|
||
| WebApplication app = builder.Build(); | ||
|
|
||
| await app.BootUmbracoAsync(); | ||
|
|
||
| app.UseUmbraco() | ||
| .WithMiddleware(u => | ||
| { | ||
| u.UseWebsite(); | ||
| }) | ||
| .WithEndpoints(u => | ||
| { | ||
| u.UseWebsiteEndpoints(); | ||
| u.UseDeliveryApiEndpoints(); | ||
| }); | ||
|
|
||
| await app.RunAsync(); | ||
| ``` | ||
| {% endcode %} | ||
|
|
||
| ## Website only | ||
|
|
||
| The following configuration is used for front-end servers that only serve rendered pages. Neither the backoffice nor the Content Delivery API is available. | ||
|
|
||
| {% code title="Program.cs" %} | ||
| ```csharp | ||
| WebApplicationBuilder builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.CreateUmbracoBuilder() | ||
| .AddCore() | ||
| .AddWebsite() | ||
| .AddComposers() | ||
| .Build(); | ||
|
|
||
| WebApplication app = builder.Build(); | ||
|
|
||
| await app.BootUmbracoAsync(); | ||
|
|
||
| app.UseUmbraco() | ||
| .WithMiddleware(u => | ||
| { | ||
| u.UseWebsite(); | ||
| }) | ||
| .WithEndpoints(u => | ||
| { | ||
| u.UseWebsiteEndpoints(); | ||
| }); | ||
|
|
||
| await app.RunAsync(); | ||
| ``` | ||
| {% endcode %} | ||
|
|
||
| ## Delivery API only | ||
|
|
||
| The following configuration is used for pure headless API servers. Only the Content Delivery API is available β no website rendering and no backoffice. | ||
|
|
||
| {% code title="Program.cs" %} | ||
| ```csharp | ||
| WebApplicationBuilder builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.CreateUmbracoBuilder() | ||
| .AddCore() | ||
| .AddDeliveryApi() | ||
| .AddComposers() | ||
| .Build(); | ||
|
|
||
| WebApplication app = builder.Build(); | ||
|
|
||
| await app.BootUmbracoAsync(); | ||
|
|
||
| app.UseUmbraco() | ||
| .WithMiddleware(u => | ||
| { | ||
| }) | ||
| .WithEndpoints(u => | ||
| { | ||
| u.UseDeliveryApiEndpoints(); | ||
| }); | ||
|
|
||
| await app.RunAsync(); | ||
| ``` | ||
| {% endcode %} | ||
|
|
||
| ## Key differences between configurations | ||
|
|
||
| ### Middleware | ||
|
|
||
| - **`UseBackOffice()`** β Registers middleware for the backoffice, including authentication and authorization. Only needed when using `AddBackOffice()`. | ||
| - **`UseWebsite()`** β Registers middleware for website rendering. Needed when using `AddWebsite()`. | ||
|
|
||
| ### Endpoints | ||
|
|
||
| - **`UseBackOfficeEndpoints()`** β Maps the Management API controllers and backoffice routes. Only needed when using `AddBackOffice()`. | ||
| - **`UseWebsiteEndpoints()`** β Maps website rendering endpoints. Needed when using `AddWebsite()`. | ||
| - **`UseDeliveryApiEndpoints()`** β Maps the Content Delivery API controllers. Use this when running the Delivery API without the backoffice. | ||
|
|
||
| {% hint style="info" %} | ||
| `UseDeliveryApiEndpoints()` is only needed when running the Delivery API **without** the backoffice. When the full backoffice is enabled, `UseBackOfficeEndpoints()` handles mapping all API controllers, including the Delivery API. | ||
| {% endhint %} | ||
|
|
||
| ## Considerations for Composers | ||
|
|
||
| When building packages or custom code using [Composers](../implementation/composing.md), be aware that some services are only available when the backoffice is enabled. If your Composer depends on backoffice-specific services, it will not work on servers configured with `AddCore()`. | ||
|
|
||
| You can check whether the backoffice is enabled by looking for the `IBackOfficeEnabledMarker` in the service collection: | ||
|
|
||
| {% code title="MyComposer.cs" %} | ||
| ```csharp | ||
| using Umbraco.Cms.Core.Composing; | ||
| using Umbraco.Cms.Core.DependencyInjection; | ||
|
|
||
| public class MyComposer : IComposer | ||
| { | ||
| public void Compose(IUmbracoBuilder builder) | ||
| { | ||
| if (builder.Services.Any(s => s.ServiceType == typeof(IBackOfficeEnabledMarker))) | ||
| { | ||
| // Register services that depend on the backoffice | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.