Meteors.DependencyInjection.AutoService 10.0.0

dotnet add package Meteors.DependencyInjection.AutoService --version 10.0.0
                    
NuGet\Install-Package Meteors.DependencyInjection.AutoService -Version 10.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Meteors.DependencyInjection.AutoService" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Meteors.DependencyInjection.AutoService" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Meteors.DependencyInjection.AutoService" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Meteors.DependencyInjection.AutoService --version 10.0.0
                    
#r "nuget: Meteors.DependencyInjection.AutoService, 10.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Meteors.DependencyInjection.AutoService@10.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Meteors.DependencyInjection.AutoService&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Meteors.DependencyInjection.AutoService&version=10.0.0
                    
Install as a Cake Tool

[Meteors] DependencyInjection.AutoService

<img alt="Nuget" src="https://img.shields.io/nuget/dt/Meteors.DependencyInjection.AutoService?color=green&logo=nuget&logoColor=blue&style=for-the-badge">

alternate text is missing from this package README image

Install-Package Meteors.DependencyInjection.AutoService -Version 10.0.0

<p align="center"> <img width="10%" src="https://user-images.githubusercontent.com/48151918/175791394-3913f060-5551-435c-adda-5bc487964f1c.png" /> </p>

Source Code


Setup

builder.Services.AddAutoService();                        // scans all assemblies
builder.Services.AddAutoService(typeof(MyClass));         // scans specific assembly
builder.Services.AddAutoService("MyProject.Services");    // scans by assembly name

[AutoService] Attribute

Place on any class to register it automatically.

Usage Behavior
[AutoService] Scoped, resolves I{ClassName} or first interface
[AutoService(ServiceLifetime.Singleton)] Singleton
[AutoService(ServiceLifetime.Transient)] Transient
[AutoService(typeof(ICustomInterface))] Registers against the specified interface
[AutoService(useImplementation: false)] Registers the class itself (no interface)
[AutoService(serviceKey: "myKey")] Keyed service registration
[AutoService(supportLazy: true)] Also registers Lazy<T> for deferred resolution

Multiple Registrations

Stack multiple [AutoService] attributes on the same class to register it against different interfaces:

[AutoService(typeof(IOther))]
[AutoService]
public class A : IA, IOther { }

// Registers:  IA     → A  (Scoped)
//             IOther → A  (Scoped)

Lazy Support

Pass supportLazy: true to also register a Lazy<T> wrapper, allowing deferred resolution:

[AutoService(supportLazy: true)]
public class A : IA { }

Both constructor injection styles now work:

public MyService(IA service) { }           // normal — resolved immediately
public MyService(Lazy service) { }     // lazy   — resolved on first .Value access

Lazy<T> is registered as Scoped to ensure the captured IServiceProvider is always the current scope — preventing root provider capture and scoped service leaks.


Interface Resolution Rules

When no implementationType is specified, the library resolves the interface in this order:

  1. Interface named I{ClassName} (e.g. class UserServiceIUserService)
  2. First direct interface on the class
  3. Throws AmbiguousMatchException if useImplementation: true but no interface found


//build.Services.AddAutoService(Assembly..namesapces..type);

build.Services.AddAutoService();

...
[AutoService(ServiceLifeTime, InterfaceType)]
[AutoService(ServiceLifeTime, InterfaceType)]
   
[AutoService()]
[AutoService(LifetimeType)]
[AutoService(ImplementationType)]
[AutoService(UseImplementation)]
[AutoService(LifetimeType,ImplementationType)]
[AutoService(LifetimeType,UseImplementation)]
[AutoService(ImplementationType,UseImplementation)] 
[AutoService(LifetimeType,ImplementationType,UseImplementation,ServiceKey)]


[AutoService] //default Scoped
class AnyService : IAnyService { }


[AutoService(typeOf(ICustomInterfaceName))] //take Implementation
class AnyService : ICustomInterfaceName { }


[AutoService(typeOf(ICustomInterfaceName1))] //take Implementation 1
class AnyService : ICustomInterfaceName,ICustomInterfaceName1,ICustomInterfaceName2 { }



[AutoService] //take Implementation IAnyService, is not first but same I + service-name
class AnyService : ICustomInterfaceName,IAnyService,ICustomInterfaceName2 { }


[AutoService] //take class
class AnyService {}

[AutoService]//as UseImplementation=true or null and take first interface
class AnyService : ICustomInterfaceName { }

[AutoService(false)] //UseImplementation=false
class AnyService : ICustomInterfaceName { }

[AutoService("servicekeyed")] //take class, and get by servicekeyed
class AnyService {}


This lib belongs to the Meteors, Meteorites helps you write less and clean code with the power of design patterns and full support for the most popular programming for perpetual projects

All you need in your project is to use meteorites, Simplicity is one in all,

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Meteors.DependencyInjection.AutoService:

Package Downloads
Meteors.AspNetCore

Build over Asp Net Core

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.0 87 3/7/2026
8.0.0 32,592 12/30/2023
6.2.2 34,925 9/3/2022
6.2.0 32,729 8/31/2022
6.0.0 32,762 7/16/2022