Skip to content

SyringeHostingExtensions

NexusLabs.Needlr.Hosting

SyringeHostingExtensions Class

Extension methods for configuring NexusLabs.Needlr.Injection.ConfiguredSyringe instances with generic host functionality.

public static class SyringeHostingExtensions

Inheritance System.Object 🡒 SyringeHostingExtensions

Example

Source-gen first (recommended for AOT/trimming):

// With module initializer bootstrap (automatic):
var host = new Syringe()
    .UsingSourceGen()
    .ForHost()
    .BuildHost();

await host.RunAsync();

Reflection-based (for dynamic scenarios):

var host = new Syringe()
    .UsingReflection()
    .ForHost()
    .BuildHost();

await host.RunAsync();

Methods

SyringeHostingExtensions.BuildHost(this ConfiguredSyringe) Method

Builds a host with the configured settings using the default HostFactory.

public static Microsoft.Extensions.Hosting.IHost BuildHost(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe);

Parameters

syringe NexusLabs.Needlr.Injection.ConfiguredSyringe

The configured syringe to build from.

Returns

Microsoft.Extensions.Hosting.IHost
The configured Microsoft.Extensions.Hosting.IHost.

Example

// Direct build without additional host configuration
var host = new Syringe()
    .UsingReflection()
    .BuildHost();

await host.RunAsync();

SyringeHostingExtensions.ForHost(this ConfiguredSyringe) Method

Transitions the configured syringe to host mode, enabling host-specific configuration.

public static NexusLabs.Needlr.Hosting.HostSyringe ForHost(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe);

Parameters

syringe NexusLabs.Needlr.Injection.ConfiguredSyringe

The configured syringe to transition.

Returns

HostSyringe
A new host syringe instance.

Example

var hostSyringe = new Syringe()
    .UsingReflection()
    .ForHost(); // Transition to host mode

// Now you can use host-specific methods
var host = hostSyringe
    .UsingOptions(() => CreateHostOptions.Default.UsingArgs(args))
    .BuildHost();