using System;
using Junction.Core.Monitoring;
using Junction.Core.Plugins;
using Junction.Core.Polling;
using Microsoft.Extensions.DependencyInjection;
namespace Junction.Core
{
///
/// DI registration for the Junction.Core orchestration stack.
///
public static class ServiceCollectionExtensions
{
///
/// Registers the Core services:
///
/// - → (singleton; scanned once at startup).
/// - → (transient; one loop per machine),
/// plus a factory the monitor uses to build engines on demand.
/// - → (singleton; the app-wide hub).
///
/// Does NOT register IMachineRepository (that is AddJunctionPersistence) nor any concrete
/// logging provider (the app host wires NLog). Logging is consumed via the
/// Microsoft.Extensions.Logging abstractions only.
///
/// The service collection to add to.
/// The same collection, for chaining.
/// is null.
public static IServiceCollection AddJunctionCore(this IServiceCollection services)
{
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}
services.AddSingleton();
// One engine per machine: transient, plus a factory the monitor calls per machine.
services.AddTransient();
services.AddSingleton>(sp => () => sp.GetRequiredService());
services.AddSingleton();
return services;
}
}
}