Files
Umbraco-CMS/src/Umbraco.Core/Composing/RuntimeAsyncComponentBase.cs
Ronald Barendse cf6137db18 Add IAsyncComponent to allow async initialize/terminate (#16536)
* Add IAsyncComponent

* Rewrite to use IAsyncComposer

* Add AsyncComponentBase and RuntimeAsyncComponentBase

* Remove manual disposing of components on restart
2024-09-23 09:45:46 +02:00

24 lines
857 B
C#

using Umbraco.Cms.Core.Services;
namespace Umbraco.Cms.Core.Composing;
/// <inheritdoc />
/// <remarks>
/// By default, the component will not execute if Umbraco is restarting or the runtime level is not <see cref="RuntimeLevel.Run" />.
/// </remarks>
public abstract class RuntimeAsyncComponentBase : AsyncComponentBase
{
private readonly IRuntimeState _runtimeState;
/// <summary>
/// Initializes a new instance of the <see cref="RuntimeAsyncComponentBase" /> class.
/// </summary>
/// <param name="runtimeState">State of the Umbraco runtime.</param>
protected RuntimeAsyncComponentBase(IRuntimeState runtimeState)
=> _runtimeState = runtimeState;
/// <inheritdoc />
protected override bool CanExecute(bool isRestarting)
=> base.CanExecute(isRestarting) && _runtimeState.Level == RuntimeLevel.Run;
}