1+ using Microsoft . Extensions . DependencyInjection ;
2+ using Microsoft . Extensions . Hosting ;
3+ using Microsoft . Extensions . Logging ;
4+ using Microsoft . Extensions . ServiceDiscovery ;
5+ using NLWebNet . Models ;
6+
7+ namespace NLWebNet . Extensions ;
8+
9+ /// <summary>
10+ /// Extension methods for .NET Aspire integration with NLWebNet
11+ /// </summary>
12+ public static class AspireExtensions
13+ {
14+ /// <summary>
15+ /// Adds NLWebNet services configured for .NET Aspire environments
16+ /// </summary>
17+ /// <param name="services">The service collection</param>
18+ /// <param name="configureOptions">Optional configuration callback for NLWebNet options</param>
19+ /// <returns>The service collection for chaining</returns>
20+ public static IServiceCollection AddNLWebNetForAspire (
21+ this IServiceCollection services ,
22+ Action < NLWebOptions > ? configureOptions = null )
23+ {
24+ // Add standard NLWebNet services
25+ services . AddNLWebNet ( configureOptions ) ;
26+
27+ // Add service discovery for Aspire
28+ services . AddServiceDiscovery ( ) ;
29+
30+ // Configure OpenTelemetry for Aspire integration
31+ services . AddNLWebNetOpenTelemetry ( builder => builder . ConfigureForAspire ( ) ) ;
32+
33+ // Add health checks optimized for Aspire
34+ services . AddHealthChecks ( )
35+ . AddCheck ( "aspire-ready" , ( ) => Microsoft . Extensions . Diagnostics . HealthChecks . HealthCheckResult . Healthy ( "Ready for Aspire" ) ) ;
36+
37+ return services ;
38+ }
39+
40+ /// <summary>
41+ /// Adds default service configuration suitable for Aspire-hosted applications
42+ /// </summary>
43+ /// <param name="builder">The host application builder</param>
44+ /// <param name="configureOptions">Optional configuration callback for NLWebNet options</param>
45+ /// <returns>The host application builder for chaining</returns>
46+ public static IHostApplicationBuilder AddNLWebNetDefaults (
47+ this IHostApplicationBuilder builder ,
48+ Action < NLWebOptions > ? configureOptions = null )
49+ {
50+ // Add NLWebNet services configured for Aspire
51+ builder . Services . AddNLWebNetForAspire ( configureOptions ) ;
52+
53+ // Configure logging for structured output
54+ builder . Logging . AddJsonConsole ( options =>
55+ {
56+ options . IncludeScopes = true ;
57+ options . TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ" ;
58+ options . UseUtcTimestamp = true ;
59+ } ) ;
60+
61+ return builder ;
62+ }
63+ }
0 commit comments