Skip to content

Fast.DependencyInjection ​

Public members, parameters, returns, and exceptions

Reference source version 3.5.36; targets: net8.0;net9.0;net10.0.

When upgrading code that uses platform flags, see the Runtime H5 migration guide and the dependency history.

Contract and constraints ​

AddDependencyInjection() scans discovered non-abstract IDependency implementations. ITransientDependency, IScopedDependency and ISingletonDependency select their respective lifetimes. IDependency alone does not select a lifetime. Types must appear in MAppContext.EffectiveTypes. Business interfaces are registered when eligible; the concrete type is used when no eligible business interface exists. Multiple interface descriptors do not guarantee the same instance across interfaces. Select one lifetime marker per implementation. Named resolution maps simple type names to actually registered business interfaces; duplicate names are rejected at registration. A singleton must not capture request-scoped services.

Installation and examples ​

Install the package ​

bash
dotnet add package Fast.DependencyInjection

Example 1 ​

csharp
using Fast.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Builder;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDependencyInjection();

var app = builder.Build();
app.MapGet("/message", (IMessageFormatter formatter) => formatter.Format("hello"));
app.Run();

public interface IMessageFormatter
{
    string Format(string value);
}

public sealed class MessageFormatter : IMessageFormatter, IScopedDependency
{
    public string Format(string value) => $"[{value}]";
}

Web-host examples belong in a consumer project using Microsoft.NET.Sdk.Web and a supported .NET target. IaaS examples can be used in an ordinary class library. Registration precedes builder.Build(); configure middleware and endpoints before app.Run(). Samples retain their original code and comments. No host, external service, database operation or client generator was run, and these snippets have not been compiled in this update.

Source reference ​

Named resolution and lifetimes ​

Name maps belong to each IServiceCollection. Named resolution uses an actually registered primary business interface and shares its singleton/scoped instance; it does not take ownership twice. Distinct interface descriptors still need not share instances. Duplicate simple names and multiple lifetime markers fail registration. Closed generic parameters are retained; string-based open-generic names require explicit closed-interface resolution.

Dependency alignment on 2026-11-02 ​

2026-11-02 dependency alignment: this package increments from 3.5.35 to 3.5.36, updating its dependency to Fast.Runtime 3.5.37. This module's implementation and public declarations are unchanged. Runtime adds mobile H5 and shifts Android and subsequent flags; migrate numeric protocols/masks, rebuild consumers and regenerate client enums. See the Runtime H5 migration guide.

2026-10-24 versions and dependencies ​

On 2026-10-24, this package increments from 3.5.32 to 3.5.33, with dependencies updated to Fast.Runtime 3.5.34. This module's own implementation and public declarations are unchanged.

Consumers using AppEnvironmentEnum must migrate numeric values and rebuild according to the Runtime HarmonyOS migration guide. This batch reviewed source and effective MSBuild package metadata only. Tests were skipped as requested; no restore, build, pack or consumer runtime validation was performed.