Introduction
One of the main strengths of Umbraco is the easiness of development, the fast learning curve and the fact that developers can be productive from the first moment they launch the project.
However, this comes at the cost of more work to make your project "production-ready", following the best practices until now..
Or better, until last summer, when a new feature was released in Umbraco v10.1: Runtime modes.
In this article I'll explain what they are, how they work, and why you should start using them immediately.
What are Runtime modes
Runtime modes are validators that ensure your project is configured correctly for the development experience you want to achieve. You can see it as automatically running specific health checks at startup.
Umbraco will automatically run the validators specific to the selected mode at startup. If some of the prerequisites for the mode are not met, Umbraco will not start and will throw a BootFailedException
.
There are currently three modes:
BackofficeDevelopment
, the default, targeted, as the name implies, to the default development experience done just using the Umbraco backoffice;Development
, the mode to use when developing using an IDE;Production
, the mode to use when running in production.
On top of having validators, runtime modes also turn some features on or off.
Let's now see in detail what each mode does.
BackofficeDevelopment
Mode
This is the default mode if nothing is specified (and probably how most people are still using Umbraco): it allows for rapid development in the backend. Your models are automatically updated in memory, and you can edit templates directly in the backend since Razor files are compiled at runtime.
Development
Mode
If you develop on Umbraco using an IDE, like Visual Studio or VS Code and the dotnet CLI, you might want to enable Development
mode, since it is the recommended setup for later using Production
mode in the actual production environment.
This mode turns off in-memory model generation and ensures the ModelsBuilder:ModelsMode
is not set to InMemoryAuto
(it won't work anyway). You should set it to either SourceCodeAuto
(to have model files generated automatically) or to SourceCodeManual
(in this case, you need to regenerate them via the dashboard). In either case, you are required to recompile your project for the changes done to Content Types to be available in your views.
The validation is done by the ModelsBuilderModeValidator
, which checks the value of ModelsMode
and fails the validation if it is set to InMemoryAuto
.
Razor views can still be compiled at runtime, like in the default mode, but it's better to start configuring your project to compile them at build-time so that you are ready to set Production
mode for the production environment. This ensures that every mistake in the views (syntax errors or referencing deleted properties or models) are reported during the build and not at runtime.
To enable Development
mode you need to change the appsettings.json
file by including these configurations: