Skip to main content
net6.0net8.0.NETStandard2.0

Fix egregiously broken or missing functionality in Microsoft.Extensions.Hosting dependency injection.

Published
Jun 22, 2026
4mo ago
Total Downloads
4.8K
4,791

Install

dotnet add package Unfucked.DI --version 0.0.1-beta.18
ProductVersions
.NET
net6.0net8.0
.NET Standard
netstandard2.0

README

đź§° Unfucked.DI

NuGet GitHub Actions Testspace Coveralls

Fix egregiously missing or broken functionality in the dependency injection/inversion of control library Microsoft.Extensions.Hosting. Inspired by Spring Framework and JSR-330.

Unfuck your house

Installation

dotnet package add Unfucked.DI
using Unfucked;
using Unfucked.DI;

Usage

Create an application using ASP.NET Core or a .NET Generic Host:

HostApplicationBuilder appBuilder = new HostApplicationBuilder(args);
using IHost app = appBuilder.Build();
await app.RunAsync();

Dependency Injection

  • Allow providers for a dependency service to be injected into a dependent instead of the service itself, which is useful when the dependent either has a longer lifetime than the dependency or needs to make multiple distinct instances of the dependency.
    appBuilder.Services
        .AddInjectableProviders()
        .AddSingleton<MyDependent>()
        .AddTransient<MyDependency>();
    
    class MyDependent(Provider<MyDependency> dependencyProvider){
        void Run(){
            using MyDependency dependency = dependencyProvider.Get();
        }
    }
    
  • Change the exit code with which the program exits when a background service crashes, instead of 0 which incorrectly indicates success.
    appBuilder.Services.SetExitCodeOnBackgroundServiceException(1);
    
  • Easily register a class in the DI context as itself and all of its interfaces and superclasses automatically, so you can inject it as any of the super types without any casting in constructors or unmaintainable multiple registration clutter.
    appBuilder.Services
        .AddSingleton<MyDependency>(alsoRegister: SuperRegistration.INTERFACES | SuperRegistration.SUPERCLASSES);
    
    class MyDependency: MyInterface;
    class MyDependent(MyInterface dependency);
    
    • Available for singletons, transients, scoped, hosted, and keyed services.

Configuration

  • In addition to searching for configuration JSON files in the current working directory, also search in the executable file's directory, so launching the program with a different CWD doesn't break configuration if that's where you're storing them.
    appBuilder.Configuration.AlsoSearchForJsonFilesInExecutableDirectory();
    
  • Don't foolishly ignore configuration files when they are hidden, system, or dot files. In fact, configuration files are often hidden (on Windows) or prefixed with a dot (on *nix).
    appBuilder.Configuration
        .AddJsonFile("conf.json", optional: false, reloadOnChange: true, includeHidden: true);
    
    appBuilder.Configuration.UnignoreHiddenFiles();
    

Logging

  • Add a colored console with single-line, column formatted data with simple type names.
    appBuilder.Logging.AddUnfuckedConsole();
    
  • Increase the log message level of specified categories/classes and event IDs, in case the author of the original class foolishly logged important messages with at most the same level as lots of unimportant messages, so you can't just decrease your logger level filter for that entire class.
    appBuilder.Logging.AmplifyMessageLevels(options =>
        options.Amplify("Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher", LogLevel.Warning, 2, 3, 5, 11, 13, 14, 15, 19, 21, 22, 23, 24));
    
  • Shorter alternatives for logging methods that aren't as ridiculously named as LogInformation, and that correctly format parameter values according to the current culture so you don't get fucked up percentages like 50 %.
    appBuilder.Logging.AddUnfuckedConsole();
    
    ILogger<MyService> logger;
    logger.Info("Transfer {progress:P0} done", 0.5); // Transfer 50% done
    

All Unfucked libraries

Changes from Previous Version

No structural changes between v0.0.1-beta.17 and v0.0.1-beta.18.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 3 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.