Summary

Class:ProjectX.Ef.IServiceCollectionExtensions
Assembly:ProjectX.Ef
File(s):C:\private\projects\projectx\backend\src\ProjectX.Ef\IServiceCollectionExtensions.cs
Covered lines:24
Uncovered lines:0
Coverable lines:24
Total lines:74
Line coverage:100%
Branch coverage:50%

History

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
AddEntityFramework(...)10100100
AddEntityFrameworkNpgsql(...)10100100
AddEntityFrameworkWriteStores(...)10100100

File(s)

C:\private\projects\projectx\backend\src\ProjectX.Ef\IServiceCollectionExtensions.cs

#LineLine coverage
 1using System;
 2using Microsoft.EntityFrameworkCore;
 3using Microsoft.Extensions.DependencyInjection;
 4using ProjectX.Ef.Stores;
 5using ProjectX.Stores;
 6using ServiceBase;
 7
 8namespace ProjectX.Ef
 9{
 10    public static class IServiceCollectionExtensions
 11    {
 12        public static IServiceCollection AddEntityFramework(
 13            this IServiceCollection services,
 14            Action<DbContextOptionsBuilder<MainDbContext>> configFunc)
 15        {
 16            // Add db context
 2417            services.AddScoped((s) =>
 2418            {
 7019                var dbBuilder = new DbContextOptionsBuilder<MainDbContext>();
 2420
 7021                 configFunc?.Invoke(dbBuilder);
 2422
 7023                var context = new AppContext();
 2424
 7025                return new MainDbContext(
 7026                    dbBuilder.Options,
 7027                    s.GetRequiredService<IDateTimeAccessor>(),
 7028                    context);
 2429            });
 30
 2431            return services;
 32        }
 33
 34        public static IServiceCollection AddEntityFrameworkNpgsql(
 35            this IServiceCollection services,
 36            string connectionString)
 37        {
 338            services.AddEntityFramework((dbBuilder) =>
 339            {
 340                dbBuilder.UseNpgsql(connectionString);
 341            });
 42
 343            return services;
 44        }
 45
 46        /// <summary>
 47        /// Registers SQL write stores
 48        /// </summary>
 49        /// <param name="services"></param>
 50        /// <returns></returns>
 51        public static IServiceCollection AddEntityFrameworkWriteStores(
 52            this IServiceCollection services)
 53        {
 2454            services.AddScoped<IUserStore, UserStore>();
 2455            services.AddScoped<IEventStore, EventStore>();
 2456            services.AddScoped<IEventCategoryStore, EventCategoryStore>();
 2457            services.AddScoped<IParticipationStore, ParticipationStore>();
 58
 2459            return services;
 60        }
 61
 62        /// <summary>
 63        /// Register SQL read stores
 64        /// </summary>
 65        /// <param name="services"></param>
 66        /// <returns></returns>
 67        // public static IServiceCollection AddEntityFrameworkReadStores(
 68        //     this IServiceCollection services)
 69        // {
 70        //     // TODO: split read and write stores
 71        //     throw new NotImplementedException();
 72        // }
 73    }
 74}