FS.AutoServiceDiscovery.Extensions 9.0.0

dotnet add package FS.AutoServiceDiscovery.Extensions --version 9.0.0
                    
NuGet\Install-Package FS.AutoServiceDiscovery.Extensions -Version 9.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="FS.AutoServiceDiscovery.Extensions" Version="9.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FS.AutoServiceDiscovery.Extensions" Version="9.0.0" />
                    
Directory.Packages.props
<PackageReference Include="FS.AutoServiceDiscovery.Extensions" />
                    
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 FS.AutoServiceDiscovery.Extensions --version 9.0.0
                    
#r "nuget: FS.AutoServiceDiscovery.Extensions, 9.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 FS.AutoServiceDiscovery.Extensions@9.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=FS.AutoServiceDiscovery.Extensions&version=9.0.0
                    
Install as a Cake Addin
#tool nuget:?package=FS.AutoServiceDiscovery.Extensions&version=9.0.0
                    
Install as a Cake Tool

FS.AutoServiceDiscovery.Extensions

NuGet Version NuGet Downloads GitHub License GitHub Stars

A powerful, convention-based automatic service discovery and registration library for .NET 9.0 applications. This library transforms manual dependency injection configuration into an intelligent, attribute-driven system that can discover, validate, and register services automatically while maintaining full control and flexibility.

🚀 Quick Start

Transform your service registration from manual configuration to intelligent automation:

// 1. Mark your services with attributes
[ServiceRegistration(ServiceLifetime.Scoped)]
public class UserService : IUserService
{
    public async Task<User> GetUserAsync(int id)
    {
        return new User { Id = id, Name = "Sample User" };
    }
}

// 2. Enable automatic discovery in Program.cs
var builder = WebApplication.CreateBuilder(args);

// Single line to automatically discover and register all services
builder.Services.AddAutoServices();

var app = builder.Build();

That's it! Your IUserService is now automatically discovered, registered, and ready for dependency injection.

🎯 Core Features

Convention-Based Discovery

Automatically discover services using intelligent naming conventions and attributes:

[ServiceRegistration(ServiceLifetime.Scoped)]
public class ProductService : IProductService { }

[ServiceRegistration(ServiceLifetime.Singleton)]
public class CacheService : ICacheService { }

Environment-Aware Registration

Register different implementations based on environment:

[ServiceRegistration(ServiceLifetime.Scoped, Profile = "Development")]
public class MockEmailService : IEmailService { }

[ServiceRegistration(ServiceLifetime.Scoped, Profile = "Production")]
public class SmtpEmailService : IEmailService { }

Expression-Based Conditional Registration

Use powerful, type-safe conditional logic:

[ConditionalService(ctx => 
    ctx.Environment.IsProduction() && 
    ctx.FeatureEnabled("AdvancedLogging") &&
    !ctx.Configuration.GetValue<bool>("MaintenanceMode"))]
[ServiceRegistration(ServiceLifetime.Scoped)]
public class AdvancedLoggingService : ILoggingService { }

Fluent Configuration API

Build complex configurations with readable, chainable syntax:

builder.Services.ConfigureAutoServices()
    .FromCurrentDomain(assembly => !assembly.FullName.StartsWith("System"))
    .WithProfile(ctx => ctx.Environment.IsDevelopment() ? "Dev" : "Prod")
    .When(ctx => ctx.FeatureEnabled("AutoDiscovery"))
    .ExcludeNamespaces("MyApp.Internal.*", "MyApp.Testing.*")
    .WithPerformanceOptimizations()
    .Apply();

High-Performance Discovery

Optimized for production with advanced caching and parallel processing:

builder.Services.AddAutoServicesWithPerformanceOptimizations(options =>
{
    options.EnableParallelProcessing = true;
    options.EnablePerformanceMetrics = true;
    options.MaxDegreeOfParallelism = 4;
});

🏗️ Architecture Overview

graph TB
    A[Service Classes] --> B[Assembly Scanner]
    B --> C[Attribute Processor]
    C --> D[Naming Convention Resolver]
    D --> E[Conditional Evaluator]
    E --> F[Plugin Coordinator]
    F --> G[Performance Cache]
    G --> H[Service Registration]
    
    I[Configuration] --> E
    J[Environment Context] --> E
    K[Feature Flags] --> E
    L[Custom Plugins] --> F
    
    style A fill:#e1f5fe
    style H fill:#c8e6c9
    style G fill:#fff3e0
    style F fill:#f3e5f5

The library follows a sophisticated pipeline architecture where each component has a specific responsibility:

  • Assembly Scanner: Efficiently discovers service candidates using reflection
  • Attribute Processor: Interprets registration attributes and metadata
  • Naming Convention Resolver: Applies intelligent interface-to-implementation mapping
  • Conditional Evaluator: Processes environment and configuration-based conditions
  • Plugin Coordinator: Manages extensible discovery strategies
  • Performance Cache: Optimizes repeated discovery operations
  • Service Registration: Final registration with dependency injection container

📚 Documentation

Core Concepts

Advanced Features

Architecture & Extensibility

🛠️ Installation

dotnet add package FS.AutoServiceDiscovery.Extensions

Requirements:

  • .NET 9.0 or later
  • Microsoft.Extensions.DependencyInjection 9.0.0+

🎨 Usage Patterns

Basic Service Registration

[ServiceRegistration(ServiceLifetime.Scoped)]
public class UserService : IUserService
{
    // Automatically registered as IUserService -> UserService
}

Profile-Based Environment Configuration

[ServiceRegistration(ServiceLifetime.Scoped, Profile = "Development")]
public class DevUserService : IUserService { }

[ServiceRegistration(ServiceLifetime.Scoped, Profile = "Production")]
public class ProdUserService : IUserService { }

Complex Conditional Logic

[ConditionalService(ctx => 
    ctx.Environment.IsProduction() && 
    ctx.Configuration.GetValue<bool>("Features:EnableCaching") &&
    ctx.EvaluateCustomCondition("DatabaseHealthy"))]
[ServiceRegistration(ServiceLifetime.Singleton)]
public class RedisCacheService : ICacheService { }

High-Performance Discovery

// Optimized for large applications
builder.Services.AddAutoServicesWithPerformanceOptimizations(options =>
{
    options.EnableParallelProcessing = true;
    options.EnablePerformanceMetrics = true;
    options.EnableLogging = false; // Reduce overhead in production
});

// Get performance statistics
var stats = PerformanceServiceCollectionExtensions.GetCacheStatistics();
Console.WriteLine($"Cache Hit Ratio: {stats.HitRatio:F1}%");

🔧 Configuration Options

Basic Configuration

builder.Services.AddAutoServices(options =>
{
    options.Profile = builder.Environment.EnvironmentName;
    options.Configuration = builder.Configuration;
    options.EnableLogging = true;
    options.IsTestEnvironment = false;
});

Advanced Performance Configuration

builder.Services.AddAutoServicesWithPerformanceOptimizations(options =>
{
    options.EnableParallelProcessing = true;
    options.MaxDegreeOfParallelism = Environment.ProcessorCount;
    options.EnablePerformanceMetrics = true;
    options.EnableLogging = false;
});

Fluent Configuration

builder.Services.ConfigureAutoServices()
    .FromAssemblies(Assembly.GetExecutingAssembly())
    .WithProfile("Production")
    .When(ctx => ctx.FeatureEnabled("AutoDiscovery"))
    .ExcludeTypes(type => type.Name.EndsWith("Test"))
    .WithDefaultLifetime(ServiceLifetime.Scoped)
    .WithPerformanceOptimizations()
    .Apply();

📊 Performance Characteristics

Feature Impact Best Use Case
Basic Discovery ~10-50ms Small to medium applications
Cached Discovery ~1-5ms Repeated discovery operations
Parallel Processing 2-4x faster Large applications (100+ services)
Plugin System Variable Complex discovery requirements

🤝 Contributing

We welcome contributions! This project is open source and benefits from community involvement:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines:

  • Follow existing code patterns and conventions
  • Add comprehensive tests for new features
  • Update documentation for any public API changes
  • Ensure backward compatibility when possible

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

Made with ❤️ by Furkan Sarıkaya

For detailed documentation, advanced usage patterns, and architectural insights, explore the comprehensive guides in our documentation directory

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.0 140 6/29/2025

Initial release for .NET 9.0 with convention-based service discovery and automatic registration.