Path: redb-route/tests/redb.Route.Tests.Xml/DiRegistrationTests.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Xml/DiRegistrationTests.cs ---- using AwesomeAssertions; using Microsoft.Extensions.DependencyInjection; using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Extensions; using redb.Route.Xml; namespace redb.Route.Tests.Xml; /// /// DI surface: XML routes registered inside AddRedbRoute(...) load through /// the standard hook — the way an ordinary ASP.NET host /// runs them, no Tsak involved. /// public class DiRegistrationTests { [Fact] public async Task AddXmlRoutesFromContent_InsideAddRedbRoute_LoadsAtContextStart() { var services = new ServiceCollection(); services.AddRedbRoute(route => route.AddXmlRoutesFromContent(""" """, "di.xml")); await using var provider = services.BuildServiceProvider(); var context = provider.GetRequiredService(); // The hosted service applies configurators before Start; the test does the same by hand. foreach (var configurator in provider.GetServices()) configurator.Configure(context); await context.Start(); try { var producer = context.GetEndpoint("direct://di-in").CreateProducer(); await producer.Start(); var exchange = new Exchange(new Message("x")); await producer.Process(exchange); context.Routes.Select(r => r.RouteId).Should().Contain("di-route"); exchange.In.Headers["via"].Should().Be("di"); } finally { await context.DisposeAsync(); } } [Fact] public async Task BrokenXml_RegisteredInDi_FailsWhenConfiguratorsApply() { var services = new ServiceCollection(); services.AddRedbRoute(route => route.AddXmlRoutesFromContent(""" """, "di-broken.xml")); await using var provider = services.BuildServiceProvider(); var context = provider.GetRequiredService(); try { var act = () => { foreach (var configurator in provider.GetServices()) configurator.Configure(context); }; act.Should().Throw().WithMessage("*di-broken.xml*nosuch*"); } finally { await context.DisposeAsync(); } } }