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
<PackageReference Include="FS.AutoServiceDiscovery.Extensions" Version="9.0.0" />
<PackageVersion Include="FS.AutoServiceDiscovery.Extensions" Version="9.0.0" />
<PackageReference Include="FS.AutoServiceDiscovery.Extensions" />
paket add FS.AutoServiceDiscovery.Extensions --version 9.0.0
#r "nuget: FS.AutoServiceDiscovery.Extensions, 9.0.0"
#:package FS.AutoServiceDiscovery.Extensions@9.0.0
#addin nuget:?package=FS.AutoServiceDiscovery.Extensions&version=9.0.0
#tool nuget:?package=FS.AutoServiceDiscovery.Extensions&version=9.0.0
FS.AutoServiceDiscovery.Extensions
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
- Getting Started Guide - Step-by-step introduction
- Service Registration - Attribute-based service marking
- Naming Conventions - Interface resolution strategies
- Conditional Registration - Environment and configuration-based logic
Advanced Features
- Fluent Configuration - Advanced configuration patterns
- Plugin Architecture - Extensible discovery mechanisms
- Performance Optimization - Caching and parallel processing
- Expression-Based Conditions - Type-safe conditional logic
Architecture & Extensibility
- System Architecture - Detailed architectural overview
- Custom Naming Conventions - Building custom resolution logic
- Plugin Development - Creating discovery extensions
- Performance Monitoring - Metrics and optimization
🛠️ 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:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - 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 | Versions 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. |
-
net9.0
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.DependencyModel (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
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.