Skip to content

Commit d401d36

Browse files
committed
Add conditional DDI_ADDSERVICES for partial class emitted for registrations
Since the user can turn off this at the static generator level, the incremental one should honor that too. This means users can turn off `AddServices` being compiled into their API by defining the preprocessor constant/directive `DDI_ADDSERVICES`.
1 parent db655f3 commit d401d36

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/DependencyInjection/IncrementalGenerator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Collections.Immutable;
44
using System.Linq;
5+
using System.Reflection;
56
using System.Text;
67
using System.Text.RegularExpressions;
78
using System.Threading;
@@ -290,6 +291,7 @@ void AddPartial(string methodName, SourceProductionContext ctx, (ImmutableArray<
290291

291292
builder.AppendLine(
292293
$$"""
294+
#if DDI_ADDSERVICES
293295
using Microsoft.Extensions.DependencyInjection.Extensions;
294296
using System;
295297
@@ -309,6 +311,7 @@ static partial class {{className}}
309311
}
310312
}
311313
}
314+
#endif
312315
""");
313316

314317
ctx.AddSource(methodName + ".g", builder.ToString().Replace("\r\n", "\n").Replace("\n", Environment.NewLine));

0 commit comments

Comments
 (0)