Skip to content

Commit 4adb7b7

Browse files
committed
Added details of database availability checks.
1 parent 944cc47 commit 4adb7b7

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

16/umbraco-cms/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@
419419
* [Custom Swagger API](reference/custom-swagger-api.md)
420420
* [Umbraco Flavored Markdown](reference/umbraco-flavored-markdown.md)
421421
* [Content Type Filters](reference/content-type-filters.md)
422+
* [Database Availability Checks](reference/database-availability.md)
422423

423424
## Tutorials
424425

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
description: Describes the checks Umbraco will do on startup to determine the availability of the database, and how this behavior can be customized.
3+
---
4+
5+
# Database Availability Checks
6+
7+
When Umbraco boots it will check for a configured database and, if found, verify that a connection can be made.
8+
9+
The default behavior is to check five times with a one second delay between attempts. If, after that, a connection cannot be established, Umbraco will fail with a `BootFailedException`.
10+
11+
## Implementing Custom Behavior
12+
13+
For projects in development with the potential for misconfigured database settings, this is likely a reasonable approach to take.
14+
15+
In production, when you have stable configuration, you may prefer to override the behavior to better handle cases where your hosting infrastructure might restart.
16+
17+
We support this by abstracting the default behavior behind the `IDatabaseAvailabilityCheck` interface found in the `Umbraco.Cms.Infrastructure.Persistence` namespace.
18+
19+
You can implement your own version of this interface and register it via a composer. This is shown in the following, stub example:
20+
21+
```csharp
22+
using Umbraco.Cms.Core.Composing;
23+
using Umbraco.Cms.Infrastructure.Persistence;
24+
25+
public class MyDatabaseAvailabilityCheckComposer : IComposer
26+
{
27+
public void Compose(IUmbracoBuilder builder)
28+
{
29+
builder.Services.AddUnique<IDatabaseAvailabilityCheck, MyDatabaseAvailabilityCheck>();
30+
}
31+
}
32+
33+
internal class MyDatabaseAvailabilityCheck : IDatabaseAvailabilityCheck
34+
{
35+
public bool IsDatabaseAvailable(IUmbracoDatabaseFactory databaseFactory)
36+
{
37+
// Provide your custom logic to check database availability, wait as required, and return true once a connection is established.
38+
return true;
39+
}
40+
}
41+
42+
```
43+
44+
For reference and inspiration, the default implementation can be found [here](https://github.com/umbraco/Umbraco-CMS/blob/main/src/Umbraco.Infrastructure/Persistence/DefaultDatabaseAvailabilityCheck.cs).
45+

0 commit comments

Comments
 (0)