Summary

Class:ProjectX.IApplicationBuilderExtensions
Assembly:ProjectX
File(s):C:\private\projects\projectx\backend\src\ProjectX\Extensions\IApplicationBuilderExtensions.cs
Covered lines:14
Uncovered lines:0
Coverable lines:14
Total lines:66
Line coverage:100%

History

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
RunOnApplicationStartedExtensions(...)40100100
RunOnApplicationStoppingExtensions(...)40100100

File(s)

C:\private\projects\projectx\backend\src\ProjectX\Extensions\IApplicationBuilderExtensions.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Builder;
 2using Microsoft.Extensions.DependencyInjection;
 3
 4namespace ProjectX
 5{
 6    /// <summary>
 7    /// Represents an application hok for the app started event
 8    /// </summary>
 9    public interface IOnApplicationStarted
 10    {
 11        void OnApplicationStarted();
 12    }
 13
 14    /// <summary>
 15    /// Represents an application hook for the app stopping event
 16    /// </summary>
 17    public interface IOnApplicationStopping
 18    {
 19        void OnApplicationStopping();
 20    }
 21
 22    public static class IApplicationBuilderExtensions
 23    {
 24        /// <summary>
 25        /// Runs all registered <see cref="IOnApplicationStarted"/> instances
 26        /// </summary>
 27        /// <param name="app"><see cref="IApplicationBuilder"/></param>
 28        public static void RunOnApplicationStartedExtensions(
 29            this IApplicationBuilder app)
 30        {
 2431            using (var serviceScope = app.ApplicationServices
 2432                   .GetRequiredService<IServiceScopeFactory>().CreateScope())
 33            {
 2434                var list = serviceScope.ServiceProvider
 2435                    .GetServices<IOnApplicationStarted>();
 36
 9237                foreach (var item in list)
 38                {
 2239                    item.OnApplicationStarted();
 40                }
 41            }
 2442        }
 43
 44        /// <summary>
 45        /// Runs all registered <see cref="IOnApplicationStopping"/> instances
 46        /// </summary>
 47        /// <param name="app"><see cref="IApplicationBuilder"/></param>
 48        public static void RunOnApplicationStoppingExtensions(
 49            this IApplicationBuilder app)
 50        {
 151            using (var serviceScope = app.ApplicationServices
 152                   .GetRequiredService<IServiceScopeFactory>().CreateScope())
 53            {
 154                var list = serviceScope.ServiceProvider
 155                    .GetServices<IOnApplicationStopping>();
 56
 457                foreach (var item in list)
 58                {
 159                    item.OnApplicationStopping();
 60                }
 61            }
 162        }
 63    }
 64}
 65
 66