This question may well have been asked before but I didn’t find anything whilst searching SO.
When using Dependency Injection, how do you normally handle types such as lists, network credentials etc.
At the moment in one of my services constructors I have:
_itemsCheckedForRelations = new List<Guid>();
_reportManagementService.Credentials = new NetworkCredential([...]);
Would you refactor these out into a custom factory class/interface and inject them or do as I’ve done here?
I’m never quite sure how to handle these types of object creation.
You can easily replace
List<Guid>withIList<Guid>orICollection<Guid>– or evenIEnumerable<Guid>if you only need to read the list.For other BCL types that don’t already implement an interface or have virtual members, you’ll need to extract an interface yourself. However, when doing that, you should watch out for Leaky Abstractions.