Skip to content

SyringeExtensionsForSemanticKernel

NexusLabs.Needlr.SemanticKernel

NexusLabs.Needlr.SemanticKernel

SyringeExtensionsForSemanticKernel Class

Extension methods for NexusLabs.Needlr.Injection.ConfiguredSyringe that enable registering Semantic Kernel infrastructure (namely IKernelFactory) as part of the Needlr build pipeline.

public static class SyringeExtensionsForSemanticKernel

Inheritance System.Object 🡒 SyringeExtensionsForSemanticKernel

Remarks

These helpers defer service registration using the Syringe post-plugin registration callback so that plugin discovery and registration are completed before the Semantic Kernel factory is added.

Note: Microsoft.SemanticKernel internally uses reflection to discover [KernelFunction] methods and create plugins. This integration therefore requires reflection and is not fully AOT-compatible. For AOT scenarios, consider registering kernel functions explicitly.

Methods

SyringeExtensionsForSemanticKernel.UsingSemanticKernel(this ConfiguredSyringe) Method

Registers an IKernelFactory built via a SemanticKernelSyringe instance.

public static NexusLabs.Needlr.Injection.ConfiguredSyringe UsingSemanticKernel(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe);

Parameters

syringe NexusLabs.Needlr.Injection.ConfiguredSyringe

The NexusLabs.Needlr.Injection.ConfiguredSyringe to augment with the registration.

Returns

NexusLabs.Needlr.Injection.ConfiguredSyringe
A new NexusLabs.Needlr.Injection.ConfiguredSyringe instance containing the registration.

Exceptions

System.ArgumentNullException
Thrown when syringe is null.

Example

var syringe = new Syringe().UsingReflection().UsingSemanticKernel();

Remarks

Use this overload when you do not need to configure Semantic Kernel.

SyringeExtensionsForSemanticKernel.UsingSemanticKernel(this ConfiguredSyringe, Func<SemanticKernelSyringe,SemanticKernelSyringe>) Method

Registers an IKernelFactory built via a configurable SemanticKernelSyringe instance.

public static NexusLabs.Needlr.Injection.ConfiguredSyringe UsingSemanticKernel(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, System.Func<NexusLabs.Needlr.SemanticKernel.SemanticKernelSyringe,NexusLabs.Needlr.SemanticKernel.SemanticKernelSyringe> configure);

Parameters

syringe NexusLabs.Needlr.Injection.ConfiguredSyringe

The NexusLabs.Needlr.Injection.ConfiguredSyringe to augment with the registration.

configure System.Func<SemanticKernelSyringe,SemanticKernelSyringe>

A delegate that receives a pre-initialized SemanticKernelSyringe (with its NexusLabs.Needlr.SemanticKernel.SemanticKernelSyringe.ServiceProvider set) and returns the configured instance used to build the kernel factory.

Returns

NexusLabs.Needlr.Injection.ConfiguredSyringe
A new NexusLabs.Needlr.Injection.ConfiguredSyringe instance containing the registration.

Exceptions

System.ArgumentNullException
Thrown when syringe or configure is null.

Example

var syringe = new Syringe()
    .UsingReflection()
    .UsingSemanticKernel(sk => sk with
    {
        // e.g., add plugins or configure options requiring the provider
        PluginTypes = new() { typeof(MyPlugin) },
    });

Remarks

Use this overload when your Semantic Kernel configuration needs access to services from the container during configuration.

SyringeExtensionsForSemanticKernel.UsingSemanticKernel(this ConfiguredSyringe, Func<SemanticKernelSyringe>) Method

Registers an IKernelFactory built via a SemanticKernelSyringe created by the supplied delegate.

public static NexusLabs.Needlr.Injection.ConfiguredSyringe UsingSemanticKernel(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, System.Func<NexusLabs.Needlr.SemanticKernel.SemanticKernelSyringe> configure);

Parameters

syringe NexusLabs.Needlr.Injection.ConfiguredSyringe

The NexusLabs.Needlr.Injection.ConfiguredSyringe to augment with the registration.

configure System.Func<SemanticKernelSyringe>

A factory that creates a fully-configured SemanticKernelSyringe used to build the kernel factory. This is useful when configuration does not need the service provider.

Returns

NexusLabs.Needlr.Injection.ConfiguredSyringe
A new NexusLabs.Needlr.Injection.ConfiguredSyringe instance containing the registration.

Exceptions

System.ArgumentNullException
Thrown when syringe or configure is null.

Example

var syringe = new Syringe()
    .UsingReflection()
    .UsingSemanticKernel(() => new SemanticKernelSyringe
    {
        // Initialize without requiring the service provider
        PluginTypes = new() { typeof(MyPlugin) },
    });