• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

net-daemon / netdaemon / 6682362857

29 Oct 2023 08:56AM UTC coverage: 79.505% (-1.2%) from 80.706%
6682362857

push

github

web-flow
Bump Roslynator.Analyzers from 4.5.0 to 4.6.1 (#960)

Bumps [Roslynator.Analyzers](https://github.com/dotnet/roslynator) from 4.5.0 to 4.6.1.
- [Release notes](https://github.com/dotnet/roslynator/releases)
- [Changelog](https://github.com/dotnet/roslynator/blob/main/ChangeLog.md)
- [Commits](https://github.com/dotnet/roslynator/compare/v4.5.0...v4.6.1)

---
updated-dependencies:
- dependency-name: Roslynator.Analyzers
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

802 of 1143 branches covered (0.0%)

Branch coverage included in aggregate %.

2895 of 3507 relevant lines covered (82.55%)

50.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.24
/src/AppModel/NetDaemon.AppModel/Common/Extensions/ServiceCollectionExtension.cs
1
using System.Reflection;
2
using NetDaemon.AppModel.Internal.AppAssemblyProviders;
3
using NetDaemon.AppModel.Internal.AppFactoryProviders;
4

5
using NetDaemon.AppModel.Internal.Config;
6

7
namespace NetDaemon.AppModel;
8

9
/// <summary>
10
///     ServiceCollection extensions
11
/// </summary>
12
public static class ServiceCollectionExtensions
13
{
14
    /// <summary>
15
    ///     Adds a single app that gets instantiated by the provided Func
16
    /// </summary>
17
    /// <param name="services">Services</param>
18
    /// <param name="factoryFunc">The Func used to create the app</param>
19
    /// <param name="id">The id of the app. This parameter is optional,
20
    ///                  by default it tries to locate the id from the specified TAppType.</param>
21
    /// <param name="focus">Whether this app has focus or not. This parameter is optional,
22
    ///                     by default it tries to check this using the FocusAttribute</param>
23
    /// <typeparam name="TAppType">The type of the app</typeparam>
24
    public static IServiceCollection AddNetDaemonApp<TAppType>(
25
        this IServiceCollection services,
26
        Func<IServiceProvider, TAppType> factoryFunc,
27
        string? id = default,
28
        bool? focus = default) where TAppType : class
29
    {
30
        return services
7✔
31
            .AddNetDaemonAppModel()
7✔
32
            .AddSingleton<IAppFactoryProvider>(SingleAppFactoryProvider.Create(factoryFunc, id, focus));
7✔
33
    }
34

35
    /// <summary>
36
    ///     Adds applications from the specified assembly
37
    /// </summary>
38
    /// <param name="services">Services</param>
39
    /// <param name="assembly">The assembly loading apps from</param>
40
    public static IServiceCollection AddAppsFromAssembly(this IServiceCollection services, Assembly assembly)
41
    {
42
        return services
20✔
43
            .AddNetDaemonAppModel()
20✔
44
            .AddSingleton<IAppAssemblyProvider>(new AppAssemblyProvider(assembly));
20✔
45
    }
46

47
    /// <summary>
48
    ///     Add a single app
49
    /// </summary>
50
    /// <param name="services">Services</param>
51
    /// <typeparam name="TAppType">The type of the app to add</typeparam>
52
    public static IServiceCollection AddNetDaemonApp<TAppType>(this IServiceCollection services)
53
    {
54
        return services.AddNetDaemonApp(typeof(TAppType));
6✔
55
    }
56

57
    /// <summary>
58
    ///     Add a single app
59
    /// </summary>
60
    /// <param name="services">Services</param>
61
    /// <param name="type">The type of the app to add</param>
62
    public static IServiceCollection AddNetDaemonApp(this IServiceCollection services, Type type)
63
    {
64
        return services
6✔
65
            .AddNetDaemonAppModel()
6✔
66
            .AddSingleton(SingleAppFactoryProvider.Create(type));
6✔
67
    }
68

69
    /// <summary>
70
    /// Adds the basic requirements for the NetDaemon application model
71
    /// </summary>
72
    /// <param name="services"></param>
73
    /// <returns></returns>
74
    public static IServiceCollection AddNetDaemonAppModel(this IServiceCollection services)
75
    {
76
        // Check if we already registered
77
        if (services.Any(n => n.ImplementationType == typeof(AppModelImpl)))
1,513✔
78
            return services;
3✔
79

80
        services
43✔
81
            .AddSingleton<AppModelImpl>()
43✔
82
            .AddSingleton<IAppModel>(s => s.GetRequiredService<AppModelImpl>())
18✔
83
            .AddTransient<AppModelContext>()
43✔
84
            .AddTransient<IAppModelContext>(s => s.GetRequiredService<AppModelContext>())
18✔
85
            .AddTransient<FocusFilter>()
43✔
86
            .AddScopedConfigurationBinder()
43✔
87
            .AddScopedAppServices()
43✔
88
            .AddConfigManagement()
43✔
89
            .AddAppFactoryIfNotExists();
43✔
90
        return services;
43✔
91
    }
92

93
    private static IServiceCollection AddAppFactoryIfNotExists(this IServiceCollection services)
94
    {
95
        if (services.Any(descriptor => descriptor.ImplementationType == typeof(AssemblyAppFactoryProvider)))
1,910!
96
            return services;
×
97

98
        return services
43✔
99
            .AddSingleton<AssemblyAppFactoryProvider>()
43✔
100
            .AddSingleton<IAppFactoryProvider>(provider => provider.GetRequiredService<AssemblyAppFactoryProvider>());
78✔
101
    }
102

103
    private static IServiceCollection AddScopedConfigurationBinder(this IServiceCollection services)
104
    {
105
        services
43✔
106
            .AddScoped<ConfigurationBinding>()
43✔
107
            .AddScoped<IConfigurationBinding>(s => s.GetRequiredService<ConfigurationBinding>());
56✔
108
        return services;
43✔
109
    }
110

111
    private static IServiceCollection AddScopedAppServices(this IServiceCollection services)
112
    {
113
        services
43✔
114
            .AddScoped<ApplicationScope>()
43✔
115
            .AddScoped(s => s.GetRequiredService<ApplicationScope>().ApplicationContext);
43✔
116
        return services;
43✔
117
    }
118

119
    private static IServiceCollection AddConfigManagement(this IServiceCollection services)
120
    {
121
        services.AddTransient(typeof(IAppConfig<>), typeof(AppConfig<>));
43✔
122
        return services;
43✔
123
    }
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc