I'm using Unity in C# for dependency injection, but the question should be applicable for any language and framework that is using dependency injection.
I'm trying to follow the SOLID-principle and therefore I got a lot of abstractions. But now I'm wondering if there's a best practice for how many injections one class should inject?
For example, I have a repository with 9 injections. Will this be hard to read for another developer?
The injections have the following responsibilities:
- IDbContextFactory - creating the context for the database.
- IMapper - Mapping from entities to domain models.
- IClock - Abstracts DateTime.Now to help with unit tests.
- IPerformanceFactory - measures the execution time for specific methods.
- ILog - Log4net for logging.
- ICollectionWrapperFactory - Creates collections (that extends IEnumerable).
- IQueryFilterFactory - Generates queries based on input that will query db.
- IIdentityHelper - Retrieves the logged in user.
- IFaultFactory - Create different FaultExceptions (I use WCF).
I'm not really dissapointed with how I delegated the responsibilities, but I'm starting to get worried for the readability.
So, my questions:
Is there a limit for how many injections a class should have? And if so, how to avoid it?
Does many injections limit readability, or does it actually improve it?