2022-05-27 10:36:39 +00:00
|
|
|
using Elsa.Features.Services;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2023-04-17 13:23:05 +00:00
|
|
|
using Microsoft.Extensions.Hosting;
|
2022-05-27 10:36:39 +00:00
|
|
|
|
|
|
|
|
namespace Elsa.Features.Abstractions;
|
|
|
|
|
|
2022-08-26 19:59:17 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Base type for classes that represent a feature.
|
|
|
|
|
/// </summary>
|
2022-05-27 10:36:39 +00:00
|
|
|
public abstract class FeatureBase : IFeature
|
|
|
|
|
{
|
2022-08-26 19:59:17 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor.
|
|
|
|
|
/// </summary>
|
2022-05-27 10:36:39 +00:00
|
|
|
protected FeatureBase(IModule module)
|
|
|
|
|
{
|
|
|
|
|
Module = module;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 19:59:17 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// The module this feature is a part of.
|
|
|
|
|
/// </summary>
|
2022-05-27 10:36:39 +00:00
|
|
|
public IModule Module { get; }
|
2022-08-26 19:59:17 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A reference to the <see cref="IServiceCollection"/> to which services can be added.
|
|
|
|
|
/// </summary>
|
2022-05-27 10:36:39 +00:00
|
|
|
public IServiceCollection Services => Module.Services;
|
|
|
|
|
|
2022-08-26 19:59:17 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Override this method to configure your feature.
|
|
|
|
|
/// </summary>
|
2022-05-27 10:36:39 +00:00
|
|
|
public virtual void Configure()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 19:59:17 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Override this method to register any hosted services provided by your feature.
|
|
|
|
|
/// </summary>
|
2022-05-27 10:36:39 +00:00
|
|
|
public virtual void ConfigureHostedServices()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 19:59:17 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Override this to register services with <see cref="Services"/>.
|
|
|
|
|
/// </summary>
|
2022-05-27 10:36:39 +00:00
|
|
|
public virtual void Apply()
|
|
|
|
|
{
|
|
|
|
|
}
|
2023-04-17 13:23:05 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Configures the specified hosted service using an optional priority to control in which order it will be registered with the service container.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="priority">The priority.</param>
|
|
|
|
|
/// <typeparam name="T">The type of hosted service to configure.</typeparam>
|
|
|
|
|
protected void ConfigureHostedService<T>(int priority = 0) where T : class, IHostedService
|
|
|
|
|
{
|
|
|
|
|
Module.ConfigureHostedService<T>(priority);
|
|
|
|
|
}
|
2022-05-27 10:36:39 +00:00
|
|
|
}
|