TaskHub.Shared

TaskHub.Shared.Refactoring - Technical Manual

The TaskHub.Shared.Refactoring module is a high-utility infrastructure tool that automates the tedious parts of .NET development: dependency injection registration and service metadata collection. It uses advanced reflection and assembly scanning to ensure that your application stays lean and consistent as it grows.

🏛 Deep Architecture

1. The Dependency Discovery Engine

The core of this module is the DependencyResolver. When the application starts, it performs a one-time scan of all loaded assemblies:

2. ServiceInfo Provider

The module provides a singleton ServiceInfo class that acts as a single source of truth for service metadata:


🛠 API Reference

DependencyBootstraper (Extension Methods)

| Method | Description | | :— | :— | | AddAppDependency<T>() | Scans for a single implementation of interface T and registers it. | | AddAppDependencies<T>() | Scans for all implementations of interface T and registers them. | | AddServiceInfo() | Registers the ServiceInfo singleton. |

[Unresolvable] Attribute

Decorate a class with this attribute to explicitly exclude it from the assembly scanning process. Useful for mock implementations or internal utility classes that shouldn’t be in the DI container.


🚀 Real-World Implementation Example

1. Automatic Repository Registration

// 1. Define Marker
public interface IOrderRepository : IRepository;

// 2. Implement
public class OrderRepository(MyDbContext db) : IOrderRepository { ... }

// 3. Register (in Program.cs or FullHostBuilder)
builder.Services.AddAppDependencies<IRepository>();

// 4. Inject anywhere
public class MyService(IOrderRepository repo) { ... }

2. Opting Out of Scanning

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

⚙️ Configuration Schema (appsettings.json)

While the logic is code-first, ServiceInfo can be influenced by the Service section:

"Service": {
  "Name": "TaskHub.ProjectService",
  "Environment": "Production"
}

👁 Telemetry & Diagnostics

Logs

During startup, the module logs:


✅ Best Practices & Anti-Patterns

🟢 Best Practices

🔴 Anti-Patterns