Skip to content

Comments

Add AssemblyNameFilter to allow to scan multiple assemblies#34

Merged
Dreamescaper merged 4 commits intomainfrom
assembly-name-filter
May 31, 2025
Merged

Add AssemblyNameFilter to allow to scan multiple assemblies#34
Dreamescaper merged 4 commits intomainfrom
assembly-name-filter

Conversation

@Dreamescaper
Copy link
Owner

@Dreamescaper Dreamescaper commented May 29, 2025

#31

Adds a new AssemblyNameFilter option to the GenerateServiceRegistrations attribute, allowing users to scan multiple assemblies, and limit which assemblies are scanned by wildcard patterns.

@Dreamescaper Dreamescaper marked this pull request as ready for review May 31, 2025 08:14
@Dreamescaper Dreamescaper requested a review from Copilot May 31, 2025 08:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a new AssemblyNameFilter option to the GenerateServiceRegistrations attribute, allowing users to limit which assemblies are scanned by wildcard patterns.

  • Introduces AssemblyNameFilter to AttributeModel and the source generator attribute class.
  • Implements GetAssembliesToScan to apply wildcard (and, per docs, comma-separated) filters.
  • Updates README and tests to demonstrate filtering by assembly name.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ServiceScan.SourceGenerator/Model/AttributeModel.cs Added AssemblyNameFilter parameter and trimming logic.
ServiceScan.SourceGenerator/GenerateAttributeSource.cs Defined new AssemblyNameFilter property with XML docs.
ServiceScan.SourceGenerator/DependencyInjectionGenerator.FilterTypes.cs Factored out GetAssembliesToScan and applied name filters.
ServiceScan.SourceGenerator.Tests/AddServicesTests.cs Renamed test and added usage example for AssemblyNameFilter.
README.md Documented the AssemblyNameFilter option in the attribute reference.
Comments suppressed due to low confidence (4)

README.md:143

  • Documentation claims support for comma-separated filters, but the code never splits on commas. Either implement comma-splitting logic in GetAssembliesToScan or update the docs to remove that claim.
| **AssemblyNameFilter** | Set this value to filter scanned assemblies by assembly name. It allows to apply an attribute to multiple assemblies. For example, this allows to scan all assemblies from your solution. You can use '*' wildcards. You can also use ',' to separate multiple filters. *Be careful to include limited amount of assemblies, as it can affect build and editor performance.* |

README.md:143

  • [nitpick] Escaping the wildcard character with a backslash (\*) may render incorrectly in markdown. Consider wrapping * in backticks or using a code span instead of a backslash.
| **AssemblyNameFilter** | Set this value to filter scanned assemblies by assembly name. It allows to apply an attribute to multiple assemblies. For example, this allows to scan all assemblies from your solution. You can use '*' wildcards. You can also use ',' to separate multiple filters. *Be careful to include limited amount of assemblies, as it can affect build and editor performance.* |

ServiceScan.SourceGenerator.Tests/AddServicesTests.cs:63

  • [nitpick] The test name is quite long and repetitive. Consider renaming to AddServicesWithAssemblyNameFilter for clarity and brevity.
public void AddServicesFromReferencedAssembliesByAssemblyNameFilter()

ServiceScan.SourceGenerator.Tests/AddServicesTests.cs:62

  • There are no tests covering multiple comma-separated filters. Consider adding a test case to verify that comma-separated patterns are both parsed and applied correctly.
[Fact]

@Dreamescaper Dreamescaper requested a review from Copilot May 31, 2025 08:37
@Dreamescaper Dreamescaper changed the title AssemblyNameFilter Add AssemblyNameFilter to allow to scan multiple assemblies May 31, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds support for filtering scanned assemblies by name (AssemblyNameFilter) and enforces exclusivity with the existing FromAssemblyOf option.

  • Introduce AssemblyNameFilter in AttributeModel, generator, tests, and docs
  • Add diagnostic and runtime check to forbid using both FromAssemblyOf and AssemblyNameFilter
  • Refactor type‐filtering logic into GetAssembliesToScan to apply name‐based patterns

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ServiceScan.SourceGenerator/Model/AttributeModel.cs Added AssemblyNameFilter property and null/whitespace handling
ServiceScan.SourceGenerator/GenerateAttributeSource.cs Documented new AssemblyNameFilter attribute and updated default behavior comment
ServiceScan.SourceGenerator/DiagnosticDescriptors.cs Introduced CantUseBothFromAssemblyOfAndAssemblyNameFilter diagnostic
ServiceScan.SourceGenerator/DependencyInjectionGenerator.ParseMethodModel.cs Enforce exclusivity of FromAssemblyOf vs AssemblyNameFilter in parsing
ServiceScan.SourceGenerator/DependencyInjectionGenerator.FilterTypes.cs Extracted GetAssembliesToScan method to apply the new filter or fallback logic
ServiceScan.SourceGenerator.Tests/AddServicesTests.cs Updated test to use AssemblyNameFilter scenario
README.md Updated table with new AssemblyNameFilter description and revised default for FromAssemblyOf
Comments suppressed due to low confidence (1)

ServiceScan.SourceGenerator.Tests/AddServicesTests.cs:86

  • Add tests covering multiple patterns in AssemblyNameFilter (e.g. comma-separated values) to verify the implementation supports all documented scenarios.
var attribute = """[GenerateServiceRegistrations(AssignableTo = typeof(Core.IService), Lifetime = ServiceLifetime.Scoped, AssemblyNameFilter="MyProduct.*")]""";

@Dreamescaper Dreamescaper merged commit 7b6c502 into main May 31, 2025
1 check passed
@Dreamescaper Dreamescaper deleted the assembly-name-filter branch May 31, 2025 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant