Skip to content

MauiAppBuilderNeedlrExtensions

NexusLabs.Needlr.Maui

MauiAppBuilderNeedlrExtensions Class

Extension methods that integrate Needlr's discovery into a user-controlled Microsoft.Maui.Hosting.MauiAppBuilder.

public static class MauiAppBuilderNeedlrExtensions

Inheritance System.Object 🡒 MauiAppBuilderNeedlrExtensions

Example

public static MauiApp CreateMauiApp()
{
    var builder = MauiApp.CreateBuilder();
    builder
        .UseMauiApp<App>()
        .UseNeedlr(syringe => syringe.UsingSourceGen());

    return builder.Build();
}

Remarks

UseNeedlr is a "reverse integration": Needlr adapts to the MAUI builder you already own rather than taking over its creation. Call it from MauiProgram.CreateMauiApp after UseMauiApp<App>(); every Needlr-discovered service is added to Microsoft.Maui.Hosting.MauiAppBuilder.Services, and MAUI builds and owns the single resulting provider.

Methods

MauiAppBuilderNeedlrExtensions.UseNeedlr(this MauiAppBuilder, ConfiguredSyringe) Method

Populates the builder's service collection with the registrations discovered by the supplied configured syringe.

public static Microsoft.Maui.Hosting.MauiAppBuilder UseNeedlr(this Microsoft.Maui.Hosting.MauiAppBuilder builder, NexusLabs.Needlr.Injection.ConfiguredSyringe syringe);

Parameters

builder Microsoft.Maui.Hosting.MauiAppBuilder

The MAUI application builder to populate.

syringe NexusLabs.Needlr.Injection.ConfiguredSyringe

A configured syringe (for example new Syringe().UsingSourceGen()).

Returns

Microsoft.Maui.Hosting.MauiAppBuilder
The same builder instance, to allow chaining.

Exceptions

System.ArgumentNullException
Thrown when any argument is null.

MauiAppBuilderNeedlrExtensions.UseNeedlr(this MauiAppBuilder, Func<Syringe,ConfiguredSyringe>) Method

Populates the builder's service collection using a syringe configured by configure. Use this overload to pick the discovery strategy inline, for example builder.UseNeedlr(s => s.UsingSourceGen()).

public static Microsoft.Maui.Hosting.MauiAppBuilder UseNeedlr(this Microsoft.Maui.Hosting.MauiAppBuilder builder, System.Func<NexusLabs.Needlr.Injection.Syringe,NexusLabs.Needlr.Injection.ConfiguredSyringe> configure);

Parameters

builder Microsoft.Maui.Hosting.MauiAppBuilder

The MAUI application builder to populate.

configure System.Func<NexusLabs.Needlr.Injection.Syringe,NexusLabs.Needlr.Injection.ConfiguredSyringe>

A callback that turns a fresh NexusLabs.Needlr.Injection.Syringe into a NexusLabs.Needlr.Injection.ConfiguredSyringe, typically by calling UsingSourceGen() or UsingReflection().

Returns

Microsoft.Maui.Hosting.MauiAppBuilder
The same builder instance, to allow chaining.

Exceptions

System.ArgumentNullException
Thrown when any argument is null.