Skip to content

MauiSyringe

NexusLabs.Needlr.Maui

MauiSyringe Class

Provides a fluent API for populating a .NET MAUI application's service collection with Needlr-discovered services. Wraps a NexusLabs.Needlr.Injection.ConfiguredSyringe with MAUI-specific behavior.

public sealed record MauiSyringe : System.IEquatable<NexusLabs.Needlr.Maui.MauiSyringe>

Inheritance System.Object 🡒 MauiSyringe

Implements System.IEquatable<MauiSyringe>

Example

var builder = MauiApp.CreateBuilder();
builder.UseMauiApp<App>();

new Syringe()
    .UsingSourceGen()
    .ForMaui()
    .PopulateInto(builder);

return builder.Build();

Remarks

A MAUI head project owns a single dependency-injection container created by MauiApp.CreateBuilder(). MauiSyringe applies every Needlr-discovered registration to that container's Microsoft.Maui.Hosting.MauiAppBuilder.Services, so MAUI resolves your App, pages, and view models — and every Needlr service — from one provider with no per-type manual registration.

Obtain a MauiSyringe by calling ForMaui() on a configured syringe.

Constructors

MauiSyringe(ConfiguredSyringe) Constructor

Initializes a new instance of the MauiSyringe class.

public MauiSyringe(NexusLabs.Needlr.Injection.ConfiguredSyringe baseSyringe);

Parameters

baseSyringe NexusLabs.Needlr.Injection.ConfiguredSyringe

The configured syringe to wrap.

Exceptions

System.ArgumentNullException
Thrown when baseSyringe is null.

Methods

MauiSyringe.PopulateInto(MauiAppBuilder) Method

Applies the Needlr-discovered registrations to the supplied Microsoft.Maui.Hosting.MauiAppBuilder's service collection, using Microsoft.Maui.Hosting.MauiAppBuilder.Configuration for options binding.

public Microsoft.Maui.Hosting.MauiAppBuilder PopulateInto(Microsoft.Maui.Hosting.MauiAppBuilder builder);

Parameters

builder Microsoft.Maui.Hosting.MauiAppBuilder

The MAUI application builder to populate.

Returns

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

Exceptions

System.ArgumentNullException
Thrown when builder is null.

Remarks

The builder's Microsoft.Maui.Hosting.MauiAppBuilder.Configuration is used to bind any [Options]- and [HttpClientOptions]-decorated types, matching the behavior of the ASP.NET and host integrations. Services already present on the builder (for example MAUI's own registrations, or your own builder.Services.Add... calls) are preserved.