I'm going to create hundreds of classes. If they all implemented the same class, do I have to register them one by one?
Example
public class Service<TEntity>: IService<TEntity> {...}
public Interface IService<TEntity> where TEntity : class {...}
public class class1 : Service<apple>, IClass1 {...}
public class class234 : Service<orange>, IClass234 {...}
In my controller I would like to inject it like this
public class FoodController : Controller{
private IClass1 _class1;
private IClass234 _class234;
FoodController(IClass1 ic1, IClass234 ic234){
_class1 = ic1;
_class234 = ic234;
}
}
I've done this before with Unity in older versions of ASP.NET How can I do this with the built in DI of ASP.NET CORE 2.0?
In the controller, I can inject the specific interface of IClass1 and IClass234 in the constructor. This is what I'm trying to achieve because I would also like to use the other methods from the other interfaces that the classes implement.
public void ConfigureServices(IServiceCollection services)
{
// Is there a way to register all 234 classes without typing out services.addTransient...
}
IEnumerable<T>// Is there a way to register all 234 classes without typing out services.addTransient...? If it is, then the link I provided and you have already seen answers your question. If your question is what your title is, then I have already answered it above, it will inject anIEnumerable<T>then you will have to use linq to find it. If that is not your question, maybe make it clearer.