GenerateTypeRegistryAttribute
NexusLabs.Needlr.Generators¶
GenerateTypeRegistryAttribute Class¶
Marks an assembly for compile-time type registry generation. The source generator will scan all referenced assemblies and generate a TypeRegistry class containing all injectable types.
Inheritance System.Object 🡒 System.Attribute 🡒 GenerateTypeRegistryAttribute
Example¶
// Include all types from NexusLabs and MyCompany namespaces
[assembly: GenerateTypeRegistry(IncludeNamespacePrefixes = new[] { "NexusLabs", "MyCompany" })]
Remarks¶
This attribute triggers the source generator to analyze all types in referenced assemblies at compile time, eliminating the need for runtime reflection-based type discovery.
Use IncludeNamespacePrefixes to filter which types
are included in the generated registry. This is similar to the
MatchingAssemblies() method in the reflection-based approach.
Properties¶
GenerateTypeRegistryAttribute.ExcludeNamespacePrefixes Property¶
Gets or sets namespace prefixes to exclude from the generated registry. Types whose namespace starts with any of these prefixes will be skipped, even if they match IncludeNamespacePrefixes.
Property Value¶
Example¶
// Include MyApp types but exclude Avalonia framework types
[assembly: GenerateTypeRegistry(
IncludeNamespacePrefixes = new[] { "MyApp" },
ExcludeNamespacePrefixes = new[] { "Avalonia" })]
// Include everything except Avalonia
[assembly: GenerateTypeRegistry(
ExcludeNamespacePrefixes = new[] { "Avalonia" })]
Remarks¶
Use this to prevent scanning framework types from libraries like Avalonia, MAUI, or other UI frameworks that expose many public types Needlr would otherwise try to register. Exclusion is applied after inclusion — if a type matches both an include prefix and an exclude prefix, it is excluded.
GenerateTypeRegistryAttribute.IncludeNamespacePrefixes Property¶
Gets or sets namespace prefix filters. Only types in namespaces starting with these prefixes will be included in the generated registry.
Property Value¶
Remarks¶
This is analogous to the MatchingAssemblies() configuration in the
reflection-based approach. If null or empty, all namespaces are included.
When both IncludeNamespacePrefixes and ExcludeNamespacePrefixes
are set, inclusion runs first, then exclusion filters out matches.
GenerateTypeRegistryAttribute.IncludeSelf Property¶
Gets or sets whether to include types from the current assembly in addition to referenced assemblies.
Property Value¶
Remarks¶
Defaults to true. Set to false to only include types
from project references.