The TaskHub.Shared.Refactoring module is a powerful tool that eliminates the need for manual dependency registration for common architectural patterns (Repositories, Services, Unit of Works).
The module uses reflection to scan your application assemblies at startup.
Use this when you have a single implementation for an interface. If multiple implementations are found, it will throw an exception to ensure deterministic behavior.
// Registers the implementation of IOrderService
builder.Services.AddAppDependency<IOrderService>();
Use this when multiple implementations are allowed and expected (e.g., event handlers, validators).
// Registers all implementations of IRepository
builder.Services.AddAppDependencies<IRepository>();
TaskHub.Shared uses the following markers for automated registration:
IService: For domain and application services.IRepository: For data access repositories.IUnitOfWork: For unit of work implementations.If you want to exclude a specific class or interface from being automatically discovered, use the [Unresolvable] attribute.
[Unresolvable]
public class MockOrderRepository : IOrderRepository { ... }
Program.cs files with hundreds of AddScoped calls.