IClock - Abstracts DateTime.Now to help with unit tests. Look at the dependencies which can be replaced by values. On the other hand, if you find a lot of domain-specific dependencies, this may indicate that the class is doing too much. Which ones are domain-specific, and which ones are “global”? For instance, I wouldn't consider ILog at the same level as IQueryFilterFactory: the first one would be available in most business classes anyway if they are using logging. Would it make sense to split it in two, three, four? Does it make sense as a whole? In order to determine if it's doing too much: Too much dependencies may indicate that the class itself is doing too much. Is there a limit for how many injections a class should have? And if so, how to avoid it?ĭoes many injections limit readability, or does it actually improve it? I'm not really dissapointed with how I delegated the responsibilities, but I'm starting to get worried for the readability. IFaultFactory - Create different FaultExceptions (I use WCF).IIdentityHelper - Retrieves the logged in user.IQueryFilterFactory - Generates queries based on input that will query db.ICollectionWrapperFactory - Creates collections (that extends IEnumerable).IPerformanceFactory - measures the execution time for specific methods.IClock - Abstracts DateTime.Now to help with unit tests.IMapper - Mapping from entities to domain models.IDbContextFactory - creating the context for the database.The injections have the following responsibilities: Will this be hard to read for another developer? But now I'm wondering if there's a best practice for how many injections one class should inject?įor example, I have a repository with 9 injections. I'm trying to follow the SOLID-principle and therefore I got a lot of abstractions. 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |