| | | 1 | | using Elsa.Features.Services; |
| | | 2 | | using Microsoft.Extensions.DependencyInjection; |
| | | 3 | | using Microsoft.Extensions.Hosting; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Features.Abstractions; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Base type for classes that represent a feature. |
| | | 9 | | /// </summary> |
| | | 10 | | public abstract class FeatureBase : IFeature |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Constructor. |
| | | 14 | | /// </summary> |
| | 44 | 15 | | protected FeatureBase(IModule module) |
| | | 16 | | { |
| | 44 | 17 | | Module = module; |
| | 44 | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// The module this feature is a part of. |
| | | 22 | | /// </summary> |
| | 208 | 23 | | public IModule Module { get; } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// A reference to the <see cref="IServiceCollection"/> to which services can be added. |
| | | 27 | | /// </summary> |
| | 154 | 28 | | public IServiceCollection Services => Module.Services; |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Override this method to configure your feature. |
| | | 32 | | /// </summary> |
| | | 33 | | public virtual void Configure() |
| | | 34 | | { |
| | 25 | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Override this method to register any hosted services provided by your feature. |
| | | 39 | | /// </summary> |
| | | 40 | | public virtual void ConfigureHostedServices() |
| | | 41 | | { |
| | 35 | 42 | | } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Override this to register services with <see cref="Services"/>. |
| | | 46 | | /// </summary> |
| | | 47 | | public virtual void Apply() |
| | | 48 | | { |
| | 4 | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Configures the specified hosted service using an optional priority to control in which order it will be register |
| | | 53 | | /// </summary> |
| | | 54 | | /// <param name="priority">The priority.</param> |
| | | 55 | | /// <typeparam name="T">The type of hosted service to configure.</typeparam> |
| | | 56 | | protected void ConfigureHostedService<T>(int priority = 0) where T : class, IHostedService |
| | | 57 | | { |
| | 1 | 58 | | Module.ConfigureHostedService<T>(priority); |
| | 1 | 59 | | } |
| | | 60 | | } |