@@ -60,29 +60,7 @@ record ServiceRegistration(int Lifetime, TypeSyntax? AssignableTo, string? FullN
6060
6161 public void Initialize ( IncrementalGeneratorInitializationContext context )
6262 {
63- var compilation = context . CompilationProvider . Select ( ( compilation , _ ) =>
64- {
65- // Add missing types as needed since we depend on the static generator potentially and can't
66- // rely on its sources being added.
67- var parse = ( CSharpParseOptions ) compilation . SyntaxTrees . FirstOrDefault ( ) . Options ;
68-
69- if ( compilation . GetTypeByMetadataName ( "Microsoft.Extensions.DependencyInjection.AddServicesNoReflectionExtension" ) is null )
70- {
71- compilation = compilation . AddSyntaxTrees (
72- CSharpSyntaxTree . ParseText ( ThisAssembly . Resources . AddServicesNoReflectionExtension . Text , parse ) ) ;
73- }
74-
75- if ( compilation . GetTypeByMetadataName ( "Microsoft.Extensions.DependencyInjection.ServiceAttribute" ) is null )
76- {
77- compilation = compilation . AddSyntaxTrees (
78- CSharpSyntaxTree . ParseText ( ThisAssembly . Resources . ServiceAttribute . Text , parse ) ,
79- CSharpSyntaxTree . ParseText ( ThisAssembly . Resources . ServiceAttribute_1 . Text , parse ) ) ;
80- }
81-
82- return compilation ;
83- } ) ;
84-
85- var types = compilation . Combine ( context . AnalyzerConfigOptionsProvider ) . SelectMany ( ( x , c ) =>
63+ var types = context . CompilationProvider . Combine ( context . AnalyzerConfigOptionsProvider ) . SelectMany ( ( x , c ) =>
8664 {
8765 ( var compilation , var options ) = x ;
8866
@@ -214,7 +192,7 @@ bool IsExport(AttributeData attr)
214192 . Collect ( ) ;
215193
216194 // Project matching service types to register with the given lifetime.
217- var conventionServices = types . Combine ( methodInvocations . Combine ( compilation ) ) . SelectMany ( ( pair , cancellationToken ) =>
195+ var conventionServices = types . Combine ( methodInvocations . Combine ( context . CompilationProvider ) ) . SelectMany ( ( pair , cancellationToken ) =>
218196 {
219197 var ( typeSymbol , ( registrations , compilation ) ) = pair ;
220198 var results = ImmutableArray . CreateBuilder < ServiceSymbol > ( ) ;
@@ -242,7 +220,7 @@ bool IsExport(AttributeData attr)
242220 . SelectMany ( ( tuple , _ ) => ImmutableArray . CreateRange ( [ tuple . Item1 , tuple . Item2 ] ) )
243221 . SelectMany ( ( items , _ ) => items . Distinct ( ) . ToImmutableArray ( ) ) ;
244222
245- RegisterServicesOutput ( context , finalServices , compilation ) ;
223+ RegisterServicesOutput ( context , finalServices , context . CompilationProvider ) ;
246224 }
247225
248226 void RegisterServicesOutput ( IncrementalGeneratorInitializationContext context , IncrementalValuesProvider < ServiceSymbol > services , IncrementalValueProvider < Compilation > compilation )
@@ -314,24 +292,7 @@ void ReportInconsistencies(SourceProductionContext context, ImmutableArray<Servi
314292 // target first (no args and wrong method name), in the predicate, before moving on to semantic analyis here.
315293
316294 var options = ( CSharpParseOptions ) invocation . SyntaxTree . Options ;
317-
318295 var compilation = semanticModel . Compilation ;
319-
320- // Add missing types as needed since we depend on the static generator potentially and can't
321- // rely on its sources being added.
322- if ( compilation . GetTypeByMetadataName ( "Microsoft.Extensions.DependencyInjection.AddServicesNoReflectionExtension" ) is null )
323- {
324- compilation = compilation . AddSyntaxTrees (
325- CSharpSyntaxTree . ParseText ( ThisAssembly . Resources . AddServicesNoReflectionExtension . Text , options ) ) ;
326- }
327-
328- if ( compilation . GetTypeByMetadataName ( "Microsoft.Extensions.DependencyInjection.ServiceAttribute" ) is null )
329- {
330- compilation = compilation . AddSyntaxTrees (
331- CSharpSyntaxTree . ParseText ( ThisAssembly . Resources . ServiceAttribute . Text , options ) ,
332- CSharpSyntaxTree . ParseText ( ThisAssembly . Resources . ServiceAttribute_1 . Text , options ) ) ;
333- }
334-
335296 var model = compilation . GetSemanticModel ( invocation . SyntaxTree ) ;
336297
337298 var symbolInfo = model . GetSymbolInfo ( invocation ) ;
0 commit comments