GeneratedPluginFactory
NexusLabs.Needlr.Injection.SourceGen¶
NexusLabs.Needlr.Injection.SourceGen.PluginFactories¶
GeneratedPluginFactory Class¶
A plugin factory that uses compile-time generated type information instead of runtime reflection for plugin discovery and instantiation.
Inheritance System.Object 🡒 GeneratedPluginFactory
Implements NexusLabs.Needlr.IPluginFactory
Remarks¶
This factory provides better performance and AOT compatibility by using pre-computed plugin information and factory delegates generated at compile time.
To use this factory, your assembly must have:
- A reference to NexusLabs.Needlr.Generators
- The [assembly: GenerateTypeRegistry(...)] attribute
Plugins are sorted by their NexusLabs.Needlr.Generators.PluginTypeInfo.Order value (lower first), then alphabetically by fully qualified type name for deterministic execution order. Sorting is performed once during initialization.
Constructors¶
GeneratedPluginFactory(Func<IReadOnlyList<PluginTypeInfo>>, bool) Constructor¶
Initializes a new instance of the GeneratedPluginFactory class with a custom plugin provider.
public GeneratedPluginFactory(System.Func<System.Collections.Generic.IReadOnlyList<NexusLabs.Needlr.Generators.PluginTypeInfo>> pluginProvider, bool allowAllWhenAssembliesEmpty=false);
Parameters¶
pluginProvider System.Func<System.Collections.Generic.IReadOnlyList<NexusLabs.Needlr.Generators.PluginTypeInfo>>
A function that returns the plugin types.
allowAllWhenAssembliesEmpty System.Boolean
When true, passing an empty assemblies collection to the factory methods will not filter plugins. This is useful for NativeAOT scenarios where producing an System.Reflection.Assembly list without reflection is not possible.
Methods¶
GeneratedPluginFactory.CreatePlugins<TPlugin,TAttribute>() Method¶
Creates instances of plugins of type TPlugin that are decorated with the specified attribute.
public System.Collections.Generic.IEnumerable<TPlugin> CreatePlugins<TPlugin,TAttribute>()
where TPlugin : class
where TAttribute : System.Attribute;
Type parameters¶
TPlugin
The plugin interface or base type to search for.
TAttribute
The attribute type to search for in the type hierarchy.
Returns¶
System.Collections.Generic.IEnumerable<TPlugin>
An enumerable of instantiated plugins implementing TPlugin and
decorated with TAttribute.
Remarks¶
Plugins are returned in order by their NexusLabs.Needlr.Generators.PluginTypeInfo.Order value (lower first), then alphabetically by fully qualified type name for deterministic execution order.
GeneratedPluginFactory.CreatePlugins<TPlugin>() Method¶
Creates instances of plugins of type TPlugin.
public System.Collections.Generic.IEnumerable<TPlugin> CreatePlugins<TPlugin>()
where TPlugin : class;
Type parameters¶
TPlugin
The plugin interface or base type to search for.
Returns¶
System.Collections.Generic.IEnumerable<TPlugin>
An enumerable of instantiated plugins implementing TPlugin.
Remarks¶
Plugins are returned in order by their NexusLabs.Needlr.Generators.PluginTypeInfo.Order value (lower first), then alphabetically by fully qualified type name for deterministic execution order.
GeneratedPluginFactory.CreatePluginsFromAssemblies<TPlugin,TAttribute>(IEnumerable<Assembly>) Method¶
Creates instances of plugins of type TPlugin from the provided assemblies that are also decorated with the specified attribute.
public System.Collections.Generic.IEnumerable<TPlugin> CreatePluginsFromAssemblies<TPlugin,TAttribute>(System.Collections.Generic.IEnumerable<System.Reflection.Assembly> assemblies)
where TPlugin : class
where TAttribute : System.Attribute;
Type parameters¶
TPlugin
The plugin interface or base type to search for.
TAttribute
The attribute type to search for in the type hierarchy.
Parameters¶
assemblies System.Collections.Generic.IEnumerable<System.Reflection.Assembly>
A collection of assemblies to scan for plugin types.
Implements CreatePluginsFromAssemblies<TPlugin,TAttribute>(IEnumerable<Assembly>)
Returns¶
System.Collections.Generic.IEnumerable<TPlugin>
An enumerable of instantiated plugins implementing TPlugin and
decorated with TAttribute.
GeneratedPluginFactory.CreatePluginsFromAssemblies<TPlugin>(IEnumerable<Assembly>) Method¶
Creates instances of plugins of type TPlugin from the provided assemblies.
public System.Collections.Generic.IEnumerable<TPlugin> CreatePluginsFromAssemblies<TPlugin>(System.Collections.Generic.IEnumerable<System.Reflection.Assembly> assemblies)
where TPlugin : class;
Type parameters¶
TPlugin
The plugin interface or base type to search for.
Parameters¶
assemblies System.Collections.Generic.IEnumerable<System.Reflection.Assembly>
A collection of assemblies to scan for plugin types.
Implements CreatePluginsFromAssemblies<TPlugin>(IEnumerable<Assembly>)
Returns¶
System.Collections.Generic.IEnumerable<TPlugin>
An enumerable of instantiated plugins implementing TPlugin.
GeneratedPluginFactory.CreatePluginsWithAttribute<TAttribute>() Method¶
Creates instances of plugins that are decorated with the specified attribute.
public System.Collections.Generic.IEnumerable<object> CreatePluginsWithAttribute<TAttribute>()
where TAttribute : System.Attribute;
Type parameters¶
TAttribute
The attribute type to search for in the type hierarchy.
Returns¶
System.Collections.Generic.IEnumerable<System.Object>
An enumerable of instantiated plugins decorated with TAttribute.
Remarks¶
Plugins are returned in order by their NexusLabs.Needlr.Generators.PluginTypeInfo.Order value (lower first), then alphabetically by fully qualified type name for deterministic execution order.
GeneratedPluginFactory.CreatePluginsWithAttributeFromAssemblies<TAttribute>(IEnumerable<Assembly>) Method¶
Creates instances of plugins from the provided assemblies that are decorated with the specified attribute.
public System.Collections.Generic.IEnumerable<object> CreatePluginsWithAttributeFromAssemblies<TAttribute>(System.Collections.Generic.IEnumerable<System.Reflection.Assembly> assemblies)
where TAttribute : System.Attribute;
Type parameters¶
TAttribute
The attribute type to search for in the type hierarchy.
Parameters¶
assemblies System.Collections.Generic.IEnumerable<System.Reflection.Assembly>
A collection of assemblies to scan for plugin types.
Implements CreatePluginsWithAttributeFromAssemblies<TAttribute>(IEnumerable<Assembly>)
Returns¶
System.Collections.Generic.IEnumerable<System.Object>
An enumerable of instantiated plugins decorated with TAttribute.