TaskHub.Shared

Automated Dependency Discovery

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).

How it Works

The module uses reflection to scan your application assemblies at startup.

  1. Scanning: It looks for all public interfaces and classes in your assemblies.
  2. Filtering: It ignores system and common vendor assemblies (like Microsoft., System.) to stay performant.
  3. Matching: It finds classes that implement specific marker interfaces or follow naming conventions.

Registration Methods

AddAppDependency

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>();

AddAppDependencies

Use this when multiple implementations are allowed and expected (e.g., event handlers, validators).

// Registers all implementations of IRepository
builder.Services.AddAppDependencies<IRepository>();

Supported Marker Interfaces

TaskHub.Shared uses the following markers for automated registration:

Opting Out

If you want to exclude a specific class or interface from being automatically discovered, use the [Unresolvable] attribute.

[Unresolvable]
public class MockOrderRepository : IOrderRepository { ... }

Benefits