There are a few options.
First, you can abandon Auto-Wiring and make the registration using a delegate, as follows:
services.AddScoped<TestDIClass1>();
services.AddScoped<TestDIClass2>();
services.AddTransient<HomeController>(c => new HomeController(
_td: c.GetRequiredService<TestDIClass2>());
Here you register both ITestDI by their concrete type. This allows the delegate for HomeController to request a specific implementation using GetRequiredService<T>.
Hand-wiring such object, however, can become cumbersome, especially when HomeController contains more dependencies, because it would require you to resolve all dependencies manually. So instead, you can make use of MS.DI's ActivatorUtilities.CreateInstance class. It implements a simplified form of MS.DI's Auto-Wiring abilities. The following snippet shows this:
services.AddScoped<TestDIClass1>();
services.AddScoped<TestDIClass2>();
services.AddTransient<HomeController>(c =>
ActivatorUtilities.CreateInstance<HomeController>(
c,
new object[]
{
c.GetRequiredService<TestDIClass2>(),
}));
In this example, HomeController is requested from ActivatorUtilities. The CreateInstance call is supplied an IServiceProvider instance (the c argument) and an array of instances to inject into HomeController's constructor. ActivatorUtilities will match the supplied objects to HomeController's constructor arguments and will resolve all missing arguments from the provided IServiceProvider.
The use of ActivatorUtilities.CreateInstance allows your registration to stay unchanged, even if new arguments are added to HomeController's constructor, for instance:
public HomeController(
ILogger logger, // new argument added
ITestDI td,
IProductService service // another argument added
)
ActivatorUtilities.CreateInstance will figure out that the resolved TestDIClass2 can be mapped to the td constructor argument, and it will resolve ILogger and IProductService from the IServiceProvider.
There are other options available, but these are in your case probably the most likely options, in case you don't want to change your design.
This information is an condensed version of the book Dependency Injection Principles. Practices, and Patterns. That contains a complete chapter on Microsoft.Extensions.DependencyInjection (MS.DI) and about 16 pages on Working with multiple components.
public HomeController(ITestDI _td), what is the logic to decide which instance to return?