Greenfield C# app reading industrial machine data over pluggable protocols. M1 walking skeleton: MTConnect plugin polls a machine, Avalonia dashboard shows live last datum. Build 0 warn/0 err on net48 + net8.0 (Linux), 115 unit tests + 2 docker-gated integration tests. Projects: - Junction.Domain (netstandard2.0): Result<T>, models, IProtocolDriver, IMachineRepository, plugin manifest. Zero package deps. - Junction.Core (netstandard2.0): PollingEngine, PluginLoader (Assembly.LoadFrom), MachineMonitor, DI extensions. - Junction.Persistence (netstandard2.0): SqliteMachineRepository (Dapper), schema, connection factory. Provider-swap seam to SQL Server. - Junction.Protocols.MTConnect (netstandard2.0): HTTP driver + namespace- version-agnostic parser (MTConnect 1.7 + 2.0). Runtime plugin. - Junction.App (net48;net8.0): Avalonia MVVM, live dashboard, NLog, DI root. - Junction.Tests (net8.0): xUnit + Moq, 117 tests. - mock/: docker-compose MTConnect agent (ladder99/agent). Target net48 for Windows 7/8 fleet compatibility. Avalonia pinned 11.3.x. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
47 lines
2.1 KiB
C#
47 lines
2.1 KiB
C#
using System;
|
|
using Junction.Core.Monitoring;
|
|
using Junction.Core.Plugins;
|
|
using Junction.Core.Polling;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Junction.Core
|
|
{
|
|
/// <summary>
|
|
/// DI registration for the Junction.Core orchestration stack.
|
|
/// </summary>
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Registers the Core services:
|
|
/// <list type="bullet">
|
|
/// <item><see cref="IPluginLoader"/> → <see cref="PluginLoader"/> (singleton; scanned once at startup).</item>
|
|
/// <item><see cref="IPollingEngine"/> → <see cref="PollingEngine"/> (transient; one loop per machine),
|
|
/// plus a <see cref="Func{IPollingEngine}"/> factory the monitor uses to build engines on demand.</item>
|
|
/// <item><see cref="IMachineMonitor"/> → <see cref="MachineMonitor"/> (singleton; the app-wide hub).</item>
|
|
/// </list>
|
|
/// Does NOT register <c>IMachineRepository</c> (that is <c>AddJunctionPersistence</c>) nor any concrete
|
|
/// logging provider (the app host wires NLog). Logging is consumed via the
|
|
/// <c>Microsoft.Extensions.Logging</c> abstractions only.
|
|
/// </summary>
|
|
/// <param name="services">The service collection to add to.</param>
|
|
/// <returns>The same collection, for chaining.</returns>
|
|
/// <exception cref="ArgumentNullException"><paramref name="services"/> is null.</exception>
|
|
public static IServiceCollection AddJunctionCore(this IServiceCollection services)
|
|
{
|
|
if (services is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(services));
|
|
}
|
|
|
|
services.AddSingleton<IPluginLoader, PluginLoader>();
|
|
|
|
// One engine per machine: transient, plus a factory the monitor calls per machine.
|
|
services.AddTransient<IPollingEngine, PollingEngine>();
|
|
services.AddSingleton<Func<IPollingEngine>>(sp => () => sp.GetRequiredService<IPollingEngine>());
|
|
|
|
services.AddSingleton<IMachineMonitor, MachineMonitor>();
|
|
|
|
return services;
|
|
}
|
|
}
|
|
}
|