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.
The core of this module is the DependencyResolver. When the application starts, it performs a one-time scan of all loaded assemblies:
IService: Registered as Scoped.IRepository: Registered as Scoped.IUnitOfWork: Registered as Scoped.AddAppDependency<T>): It finds the exact implementation of interface T. If zero or >1 implementations are found, it throws a DependencyResolutionException, preventing ambiguous runtime behavior.AddAppDependencies<T>): It finds all classes implementing interface T and registers them as an IEnumerable<T>.The module provides a singleton ServiceInfo class that acts as a single source of truth for service metadata:
AssemblyInformationalVersionAttribute to determine the service version.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] AttributeDecorate 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.
// 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) { ... }
[Unresolvable]
public class TemporaryMockRepo : IOrderRepository { ... }
appsettings.json)While the logic is code-first, ServiceInfo can be influenced by the Service section:
"Service": {
"Name": "TaskHub.ProjectService",
"Environment": "Production"
}
During startup, the module logs:
DependencyResolver: “Found {Count} implementations for {InterfaceName}”.ServiceInfo: “Service {Name} version {Version} started on .NET {Runtime}”.IService or IRepository for any new infrastructure or domain service to leverage auto-registration.AddAppDependency<T> pattern to catch accidental duplicate implementations early.