| | | 1 | | using Carter; |
| | | 2 | | |
| | | 3 | | using Microsoft.Extensions.Logging; |
| | | 4 | | |
| | | 5 | | using NexusLabs.Needlr.AspNet; |
| | | 6 | | |
| | | 7 | | namespace NexusLabs.Needlr.Carter; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Plugin that registers Carter services with the web application builder. |
| | | 11 | | /// Automatically adds Carter module support to the ASP.NET Core application. |
| | | 12 | | /// </summary> |
| | | 13 | | public sealed class CarterWebApplicationBuilderPlugin : IWebApplicationBuilderPlugin |
| | | 14 | | { |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public void Configure(WebApplicationBuilderPluginOptions options) |
| | | 17 | | { |
| | 11 | 18 | | ArgumentNullException.ThrowIfNull(options); |
| | | 19 | | |
| | 9 | 20 | | options.Logger.LogInformation("Configuring Carter services..."); |
| | | 21 | | |
| | | 22 | | // Disable Carter's own assembly scan for ICarterModule implementers: Needlr's type |
| | | 23 | | // registry is the single source of truth for module registration. Without this, a |
| | | 24 | | // public module is discovered by BOTH Carter and Needlr and mapped twice, which |
| | | 25 | | // surfaces as an AmbiguousMatchException at request time. MapCarter() maps whatever |
| | | 26 | | // ICarterModule services are in the container, so Needlr-registered modules still map. |
| | 18 | 27 | | options.Builder.Services.AddCarter(configurator: configurator => configurator.WithEmptyModules()); |
| | | 28 | | |
| | 9 | 29 | | options.Logger.LogInformation("Carter services configured successfully."); |
| | 9 | 30 | | } |
| | | 31 | | } |