Skip to content

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.

public sealed class GenerateTypeRegistryAttribute : System.Attribute

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.IncludeNamespacePrefixes Property

Gets or sets namespace prefix filters. Only types in namespaces starting with these prefixes will be included in the generated registry.

public string[]? IncludeNamespacePrefixes { get; set; }

Property Value

System.String[]

Remarks

This is analogous to the MatchingAssemblies() configuration in the reflection-based approach. If null or empty, all namespaces are included.

GenerateTypeRegistryAttribute.IncludeSelf Property

Gets or sets whether to include types from the current assembly in addition to referenced assemblies.

public bool IncludeSelf { get; set; }

Property Value

System.Boolean

Remarks

Defaults to true. Set to false to only include types from project references.