Skip to content

InjectableTypeInfo

NexusLabs.Needlr.Generators

InjectableTypeInfo Struct

Represents metadata about an injectable type discovered at compile time.

public readonly struct InjectableTypeInfo

Remarks

This struct is used by the generated TypeRegistry to provide type information without requiring reflection at runtime.

Constructors

InjectableTypeInfo(Type, IReadOnlyList<Type>) Constructor

Initializes a new instance of InjectableTypeInfo.

public InjectableTypeInfo(System.Type type, System.Collections.Generic.IReadOnlyList<System.Type> interfaces);

Parameters

type System.Type

The concrete implementation type.

interfaces System.Collections.Generic.IReadOnlyList<System.Type>

The interfaces implemented by the type that should be registered.

InjectableTypeInfo(Type, IReadOnlyList<Type>, Nullable<InjectableLifetime>) Constructor

Initializes a new instance of InjectableTypeInfo.

public InjectableTypeInfo(System.Type type, System.Collections.Generic.IReadOnlyList<System.Type> interfaces, System.Nullable<NexusLabs.Needlr.Generators.InjectableLifetime> lifetime);

Parameters

type System.Type

The concrete implementation type.

interfaces System.Collections.Generic.IReadOnlyList<System.Type>

The interfaces implemented by the type that should be registered.

lifetime System.Nullable<InjectableLifetime>

The pre-computed service lifetime, or null if not determined.

InjectableTypeInfo(Type, IReadOnlyList<Type>, Nullable<InjectableLifetime>, Func<IServiceProvider,object>) Constructor

Initializes a new instance of InjectableTypeInfo.

public InjectableTypeInfo(System.Type type, System.Collections.Generic.IReadOnlyList<System.Type> interfaces, System.Nullable<NexusLabs.Needlr.Generators.InjectableLifetime> lifetime, System.Func<System.IServiceProvider,object>? factory);

Parameters

type System.Type

The concrete implementation type.

interfaces System.Collections.Generic.IReadOnlyList<System.Type>

The interfaces implemented by the type that should be registered.

lifetime System.Nullable<InjectableLifetime>

The pre-computed service lifetime, or null if not determined.

factory System.Func<System.IServiceProvider,System.Object>

A factory delegate that creates an instance of the type using the service provider. When provided, enables AOT-compatible instantiation without runtime reflection.

InjectableTypeInfo(Type, IReadOnlyList<Type>, Nullable<InjectableLifetime>, Func<IServiceProvider,object>, IReadOnlyList<string>) Constructor

Initializes a new instance of InjectableTypeInfo with keyed service support.

public InjectableTypeInfo(System.Type type, System.Collections.Generic.IReadOnlyList<System.Type> interfaces, System.Nullable<NexusLabs.Needlr.Generators.InjectableLifetime> lifetime, System.Func<System.IServiceProvider,object>? factory, System.Collections.Generic.IReadOnlyList<string> serviceKeys);

Parameters

type System.Type

The concrete implementation type.

interfaces System.Collections.Generic.IReadOnlyList<System.Type>

The interfaces implemented by the type that should be registered.

lifetime System.Nullable<InjectableLifetime>

The pre-computed service lifetime, or null if not determined.

factory System.Func<System.IServiceProvider,System.Object>

A factory delegate that creates an instance of the type using the service provider. When provided, enables AOT-compatible instantiation without runtime reflection.

serviceKeys System.Collections.Generic.IReadOnlyList<System.String>

The service keys from [Keyed] attributes. When provided, the type will be registered as a keyed service in addition to its normal registration.

Properties

InjectableTypeInfo.Factory Property

Gets a factory delegate that creates an instance of the type using the service provider.

public System.Func<System.IServiceProvider,object>? Factory { get; }

Property Value

System.Func<System.IServiceProvider,System.Object>

Remarks

When this delegate is provided, the type registrar can use it to create instances without relying on Activator.CreateInstance or reflection-based constructor invocation. This is essential for NativeAOT scenarios where reflection may be disabled.

The factory receives an System.IServiceProvider and should resolve all constructor dependencies from it before creating the instance.

InjectableTypeInfo.Interfaces Property

Gets the interfaces implemented by the type that should be registered.

public System.Collections.Generic.IReadOnlyList<System.Type> Interfaces { get; }

Property Value

System.Collections.Generic.IReadOnlyList<System.Type>

InjectableTypeInfo.Lifetime Property

Gets the pre-computed service lifetime for this type, or null if the lifetime should be determined at runtime by an ITypeFilterer.

public System.Nullable<NexusLabs.Needlr.Generators.InjectableLifetime> Lifetime { get; }

Property Value

System.Nullable<InjectableLifetime>

Remarks

When this value is set, the type registrar can skip runtime reflection for constructor analysis, improving startup performance and enabling AOT compilation scenarios.

InjectableTypeInfo.ServiceKeys Property

Gets the service keys from [Keyed] attributes on this type.

public System.Collections.Generic.IReadOnlyList<string> ServiceKeys { get; }

Property Value

System.Collections.Generic.IReadOnlyList<System.String>

Remarks

When service keys are present, the type will be registered as a keyed service in addition to its normal registration. Consumers can then resolve the specific implementation using [FromKeyedServices("key")] on constructor parameters.

A type can have multiple keys, resulting in multiple keyed registrations for the same implementation.

InjectableTypeInfo.Type Property

Gets the concrete implementation type.

public System.Type Type { get; }

Property Value

System.Type