| | | 1 | | using Microsoft.Extensions.DependencyInjection; |
| | | 2 | | using NexusLabs.Needlr; |
| | | 3 | | |
| | | 4 | | namespace MultiProjectApp.Features.Reporting; |
| | | 5 | | |
| | | 6 | | /// <summary>Generates simple text reports.</summary> |
| | | 7 | | public interface IReportService |
| | | 8 | | { |
| | | 9 | | string Generate(string title, IEnumerable<string> items); |
| | | 10 | | } |
| | | 11 | | |
| | | 12 | | /// <summary>Stub implementation of <see cref="IReportService"/>.</summary> |
| | | 13 | | public sealed class ConsoleReportService : IReportService |
| | | 14 | | { |
| | | 15 | | public string Generate(string title, IEnumerable<string> items) |
| | | 16 | | { |
| | 0 | 17 | | var lines = items.ToList(); |
| | 0 | 18 | | return $"=== {title} ===\n{string.Join("\n", lines.Select((l, i) => $" {i + 1}. {l}"))}\n({lines.Count} items)" |
| | | 19 | | } |
| | | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Helper class intentionally decorated with [DoNotAutoRegister] — this is the correct |
| | | 24 | | /// usage pattern: preventing a non-plugin helper from being auto-registered as a DI service. |
| | | 25 | | /// Compare with the Bootstrap project which shows the INCORRECT (and now warned) usage. |
| | | 26 | | /// </summary> |
| | | 27 | | [DoNotAutoRegister] |
| | | 28 | | public sealed class ReportingInternals |
| | | 29 | | { |
| | | 30 | | public static string FormatHeader(string title) => $"=== {title} ==="; |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <summary>Registers reporting services into the DI container.</summary> |
| | | 34 | | public sealed class ReportingPlugin : IServiceCollectionPlugin |
| | | 35 | | { |
| | | 36 | | public void Configure(ServiceCollectionPluginOptions options) |
| | | 37 | | { |
| | | 38 | | options.Services.AddSingleton<IReportService, ConsoleReportService>(); |
| | | 39 | | } |
| | | 40 | | } |