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

DemoBytom / DemoEngine / 23381010346

21 Mar 2026 01:42PM UTC coverage: 32.468% (+0.02%) from 32.451%
23381010346

push

coveralls.net

DemoBytom
Migrated away from `Autofac` and `MediatR`

`Autofac` removed completely as it's not really needed anymore
`MediatR` replaced with `Mediator`. `Mediator` is source generated, MIT licensed, and generally faster.

I plan to decouple rendering services (like `GPass`, or `ShaderManager`) from eachother using mediator pattern, to solve the current issue with asynchronous construction - shader compiler requires asynchronous compilation, shader manager loads shaders from disc asynchronously etc...

1263 of 3890 relevant lines covered (32.47%)

0.36 hits per line

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

0.0
/src/Demo.Engine.Core/Services/EngineService.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.Reflection;
5
using Demo.Engine.Core.Features.StaThread;
6
using Demo.Engine.Core.Interfaces;
7
using Microsoft.Extensions.DependencyInjection;
8
using Microsoft.Extensions.Hosting;
9
using Microsoft.Extensions.Logging;
10

11
namespace Demo.Engine.Core.Services;
12

13
internal sealed class EngineService(
×
14
    ILogger<EngineService> logger,
×
15
    IHostApplicationLifetime hostApplicationLifetime,
×
16
    IServiceScopeFactory scopeFactory)
×
17
    : IHostedService,
18
      IDisposable
19
{
20
    private readonly ILogger<EngineService> _logger = logger;
×
21
    private readonly IHostApplicationLifetime _hostApplicationLifetime = hostApplicationLifetime;
×
22
    private readonly IServiceScopeFactory _scopeFactory = scopeFactory;
×
23
    private readonly string _serviceName = "Engine";
×
24
    private Task? _executingTask;
25
    private bool _stopRequested;
26
    private bool _disposedValue;
27

28
    private readonly string _version = Assembly
×
29
        .GetEntryAssembly()
×
30
        ?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
×
31
        ?.InformationalVersion ?? "0.0.0";
×
32

33
    public Task StartAsync(CancellationToken cancellationToken)
34
    {
35
        _logger.LogServiceIsStarting(_serviceName, _version);
×
36
        _executingTask = DoWorkAsync();
×
37

38
        return _executingTask.IsCompleted
×
39
            ? _executingTask
×
40
            : Task.CompletedTask;
×
41
    }
42

43
    public async Task StopAsync(CancellationToken cancellationToken)
44
    {
45
        _logger.LogServiceStopping(_serviceName);
×
46

47
        _stopRequested = true;
×
48
        if (_executingTask is null)
×
49
        {
50
            return;
×
51
        }
52

53
        _ = await Task.WhenAny(
×
54
            _executingTask,
×
55
            Task.Delay(Timeout.Infinite, cancellationToken));
×
56
    }
×
57

58
    private async Task DoWorkAsync()
59
    {
60
        await using var scope = _scopeFactory.CreateAsyncScope();
×
61
        var serviceProvider = scope.ServiceProvider;
×
62
        var mainLoopLifetime = serviceProvider.GetService<IMainLoopLifetime>();
×
63

64
        try
65
        {
66
            //var osMessageHandler = serviceProvider.GetRequiredService<IOSMessageHandler>();
67
            //var renderingEngine = serviceProvider.GetRequiredService<IRenderingEngine>();
68

69
            var mainLoopService = serviceProvider.GetRequiredService<IMainLoopService>();
×
70
            var executeAsync = mainLoopService.ExecutingTask;
×
71

72
            var staThreadService = serviceProvider.GetRequiredService<IStaThreadService>();
×
73
            var runStaThread = staThreadService.ExecutingTask;
×
74

75
            await Task.WhenAll(
×
76
                [
×
77
                    executeAsync,
×
78
                    runStaThread
×
79
                ]);
×
80
        }
×
81
        catch (OperationCanceledException)
×
82
        {
83
            mainLoopLifetime?.Cancel();
×
84
        }
×
85
        catch (Exception ex)
×
86
        {
87
            _logger.LogServiceFailedWithError(ex, _serviceName);
×
88
        }
×
89
        finally
90
        {
91
            if (!_stopRequested)
×
92
            {
93
                _hostApplicationLifetime.StopApplication();
×
94
            }
95
        }
96
    }
×
97

98
    private void Dispose(bool disposing)
99
    {
100
        if (!_disposedValue)
×
101
        {
102
            if (disposing)
×
103
            {
104
                _hostApplicationLifetime.StopApplication();
×
105
            }
106

107
            _disposedValue = true;
×
108
        }
109
    }
×
110

111
    public void Dispose()
112
    {
113
        // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
114
        Dispose(disposing: true);
×
115
        GC.SuppressFinalize(this);
×
116
    }
×
117
}
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