using Microsoft.Extensions.DependencyInjection; using ZB.MOM.WW.ScadaBridge.SiteRuntime; using ZB.MOM.WW.ScadaBridge.SiteRuntime.Scripts; namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests; /// /// Pins the DI lifetimes that carry a behavioural contract rather than a convention. /// public class SiteRuntimeServiceRegistrationTests { /// /// Register row 100. ScriptCompilationService owns the /// SiteScriptCompileCache, so "one Roslyn compile per script body per process" /// (N4 / WP3.1's warm-then-gate deploy path) is precisely the statement that DI hands /// out ONE of these per host. The cache stopped being static when row 100 removed /// the process-global state tests were clobbering; this registration is what replaced /// the static as the guarantee, so it is pinned here. /// /// Downgrading this to Scoped or Transient would give every consumer — the deploy /// gate, each Instance Actor's PreStart, SharedScriptLibrary — its own empty cache and /// silently reintroduce the recompile storms WP3.1 removed, with no functional test /// failing. This assertion is the only thing that would notice. /// [Fact] public void AddSiteRuntime_RegistersScriptCompilationServiceAsSingleton_SoOneCompileCacheExistsPerProcess() { var services = new ServiceCollection(); services.AddSiteRuntime(); var descriptor = Assert.Single( services, d => d.ServiceType == typeof(ScriptCompilationService)); Assert.Equal(ServiceLifetime.Singleton, descriptor.Lifetime); } }