ServiceCollectionAgentFrameworkExtensions
NexusLabs.Needlr.AgentFramework¶
NexusLabs.Needlr.AgentFramework¶
ServiceCollectionAgentFrameworkExtensions Class¶
Extension methods for Microsoft.Extensions.DependencyInjection.IServiceCollection that register the Needlr Agent Framework infrastructure directly, without requiring the NexusLabs.Needlr.Injection.ConfiguredSyringe fluent builder.
Inheritance System.Object 🡒 ServiceCollectionAgentFrameworkExtensions
Remarks¶
Use this when registering the agent framework from an NexusLabs.Needlr.IServiceCollectionPlugin so that feature projects can self-register without modifying the composition root:
public sealed class AgentFrameworkPlugin : IServiceCollectionPlugin
{
public void Configure(ServiceCollectionPluginOptions options)
{
options.Services.AddNeedlrAgentFramework();
}
}
The configure overloads let plugins own the full agent-framework configuration surface (custom Microsoft.Extensions.AI.IChatClient, metrics meter / activity source names, diagnostics, token budget tracking, etc.) without exfiltrating that configuration to the composition root:
public sealed class AgentFrameworkPlugin : IServiceCollectionPlugin
{
public void Configure(ServiceCollectionPluginOptions options)
{
options.Services.AddNeedlrAgentFramework(af => af
.ConfigureMetrics(o =>
{
o.MeterName = "MyApp.Agents";
o.ActivitySourceName = "MyApp.Agents";
}));
}
}
All overloads call the same code path as UsingAgentFramework(this ConfiguredSyringe) — zero duplication, zero drift between the two entry points.
When both this entry point and UsingAgentFramework are used in the same application,
the first registration wins (TryAddSingleton semantics). Configuration delegates
supplied by later registrations are silently discarded.
Methods¶
ServiceCollectionAgentFrameworkExtensions.AddNeedlrAgentFramework(this IServiceCollection) Method¶
Registers the full Needlr Agent Framework infrastructure on the service collection.
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddNeedlrAgentFramework(this Microsoft.Extensions.DependencyInjection.IServiceCollection services);
Parameters¶
services Microsoft.Extensions.DependencyInjection.IServiceCollection
The service collection to register into.
Returns¶
Microsoft.Extensions.DependencyInjection.IServiceCollection
The same services instance for chaining.
ServiceCollectionAgentFrameworkExtensions.AddNeedlrAgentFramework(this IServiceCollection, Func<AgentFrameworkSyringe,AgentFrameworkSyringe>) Method¶
Registers the full Needlr Agent Framework infrastructure on the service collection with a configurable AgentFrameworkSyringe.
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddNeedlrAgentFramework(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Func<NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe,NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe> configure);
Parameters¶
services Microsoft.Extensions.DependencyInjection.IServiceCollection
The service collection to register into.
configure System.Func<AgentFrameworkSyringe,AgentFrameworkSyringe>
A delegate that receives a pre-initialized AgentFrameworkSyringe (with its NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe.ServiceProvider set) and returns the configured instance used to build the agent factory. Invoked lazily the first time NexusLabs.Needlr.AgentFramework.BuiltAgentFrameworkSyringe is resolved.
Returns¶
Microsoft.Extensions.DependencyInjection.IServiceCollection
The same services instance for chaining.
Exceptions¶
System.ArgumentNullException
Thrown when services or configure is null.
ServiceCollectionAgentFrameworkExtensions.AddNeedlrAgentFramework(this IServiceCollection, Func<AgentFrameworkSyringe>) Method¶
Registers the full Needlr Agent Framework infrastructure on the service collection using an AgentFrameworkSyringe created by the supplied factory.
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddNeedlrAgentFramework(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Func<NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe> configure);
Parameters¶
services Microsoft.Extensions.DependencyInjection.IServiceCollection
The service collection to register into.
configure System.Func<AgentFrameworkSyringe>
A factory that creates a fully-configured AgentFrameworkSyringe used to build the agent factory. Useful when configuration does not need the service provider. Routes through the AddNeedlrAgentFramework(this IServiceCollection, Func<AgentFrameworkSyringe,AgentFrameworkSyringe>) overload so both paths share the same NexusLabs.Needlr.AgentFramework.BuiltAgentFrameworkSyringe construction and progress sink wiring.
Returns¶
Microsoft.Extensions.DependencyInjection.IServiceCollection
The same services instance for chaining.
Exceptions¶
System.ArgumentNullException
Thrown when services or configure is null.