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

DemoBytom / DemoEngine / 13818869862

12 Mar 2025 06:29PM UTC coverage: 9.651% (-0.1%) from 9.797%
13818869862

push

coveralls.net

DemoBytom
Add a STAThreadWriter

Added a class that manages writing messages to STAThreadService
Added a ObjectPool for reusing DoEventsOkRequests

227 of 2352 relevant lines covered (9.65%)

17700.98 hits per line

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

0.0
/src/Demo.Engine.Core/RegistrationExtensions.cs
1
// Copyright © Michał Dembski and contributors.
2
// Distributed under MIT license. See LICENSE file in the root for more information.
3

4
using System.Threading.Channels;
5
using Demo.Engine.Core.Components.Keyboard.Internal;
6
using Demo.Engine.Core.Interfaces;
7
using Demo.Engine.Core.Interfaces.Components;
8
using Demo.Engine.Core.Interfaces.Platform;
9
using Demo.Engine.Core.Platform;
10
using Demo.Engine.Core.Services;
11
using Microsoft.Extensions.DependencyInjection;
12
using Microsoft.Extensions.DependencyInjection.Extensions;
13
using Microsoft.Extensions.ObjectPool;
14

15
namespace Demo.Engine.Core;
16

17
public static class RegistrationExtensions
18
{
19
    public static IServiceCollection AddEngineCore(
20
        this IServiceCollection services)
21
    {
22
        _ = services
×
23
                .AddScoped<IMainLoopService, MainLoopService>()
×
24
                .AddSingleton<IKeyboardCache, KeyboardCache>()
×
25
                .AddTransient<IFpsTimer, FpsTimer>()
×
26
                .AddTransient<IContentFileProvider, ContentFileProvider>()
×
27
                .AddHostedService<EngineServiceNew>()
×
28
                .AddScoped<IMainLoopLifetime, MainLoopLifetime>()
×
29
                .AddScoped<IStaThreadService, StaThreadService>()
×
30
                .AddScoped<ILoopJob, LoopJob>()
×
31
                .AddScoped<IMainLoopServiceNew, MainLoopServiceNew>()
×
32
                .AddScopedBoundedChannel<StaThreadRequests>(
×
33
                    new BoundedChannelOptions(10)
×
34
                    {
×
35
                        AllowSynchronousContinuations = false,
×
36
                        FullMode = BoundedChannelFullMode.Wait,
×
37
                        SingleReader = true,
×
38
                        SingleWriter = false,
×
39
                    })
×
40
            .AddScoped<IStaThreadWriter, StaThreadWriter>()
×
41
            ;
×
42

43
        services
×
44
            .TryAddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();
×
45
        services
×
46
            .TryAddSingleton(sp
×
47
                =>
×
48
            {
×
49
                var provider = sp.GetRequiredService<ObjectPoolProvider>();
×
50
                var policy = new DefaultPooledObjectPolicy<StaThreadRequests.DoEventsOkRequest>();
×
51

×
52
                var created = provider.Create(policy);
×
53

×
54
                return created;
×
55
            });
×
56

57
        return services;
×
58
    }
59

60
    private static IServiceCollection AddScopedBoundedChannel<T>(
61
        this IServiceCollection services,
62
            BoundedChannelOptions options)
63
        => services
×
64
            .AddScoped(_
×
65
                => Channel.CreateBounded<T>(
×
66
                    options))
×
67
            .AddScoped(sp
×
68
                => sp.GetRequiredService<Channel<T>>().Reader)
×
69
            .AddScoped(sp
×
70
                => sp.GetRequiredService<Channel<T>>().Writer)
×
71
        ;
72
}
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

© 2026 Coveralls, Inc