Skip to content

SyringeAspNetExtensions

NexusLabs.Needlr.AspNet

SyringeAspNetExtensions Class

Extension methods for configuring NexusLabs.Needlr.Injection.ConfiguredSyringe instances with ASP.NET Core functionality.

public static class SyringeAspNetExtensions

Inheritance System.Object 🡒 SyringeAspNetExtensions

Example

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

// With module initializer bootstrap (automatic):
var webApplication = new Syringe()
    .UsingSourceGen()
    .ForWebApplication()
    .BuildWebApplication();

await webApplication.RunAsync();

Reflection-based (for dynamic scenarios):

var webApplication = new Syringe()
    .UsingReflection()
    .ForWebApplication()
    .BuildWebApplication();

await webApplication.RunAsync();

Methods

SyringeAspNetExtensions.BuildWebApplication(this ConfiguredSyringe) Method

Builds a web application with the configured settings using the default WebApplicationFactory.

public static Microsoft.AspNetCore.Builder.WebApplication BuildWebApplication(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe);

Parameters

syringe NexusLabs.Needlr.Injection.ConfiguredSyringe

The configured syringe to build from.

Returns

Microsoft.AspNetCore.Builder.WebApplication
The configured Microsoft.AspNetCore.Builder.WebApplication.

Example

// Direct build without additional web configuration
var webApplication = new Syringe()
    .UsingReflection()
    .BuildWebApplication();

await webApplication.RunAsync();

SyringeAspNetExtensions.ForWebApplication(this ConfiguredSyringe) Method

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

public static NexusLabs.Needlr.AspNet.WebApplicationSyringe ForWebApplication(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe);

Parameters

syringe NexusLabs.Needlr.Injection.ConfiguredSyringe

The configured syringe to transition.

Returns

WebApplicationSyringe
A new web application syringe instance.

Example

var webAppSyringe = new Syringe()
    .UsingReflection()
    .ForWebApplication(); // Transition to web application mode

// Now you can use web-specific methods
var webApp = webAppSyringe
    .UsingOptions(() => CreateWebApplicationOptions.Default.UsingCliArgs(args))
    .BuildWebApplication();