Dependency Injection for Built-in Types

This question may have been asked before, but I did not find anything while searching for SO.

When using Injection Dependency, as usual, you handle types such as lists, network credentials, etc.

At the moment, in one of my service designers, I:

_itemsCheckedForRelations = new List<Guid>(); _reportManagementService.Credentials = new NetworkCredential([...]); 

Could you reorganize them into a user factory class / interface and introduce them or do as I did here?

I am never sure how to handle these types of object creation.

+4
source share
2 answers

You can easily replace List<Guid> with IList<Guid> or ICollection<Guid> - or even IEnumerable<Guid> if you only need to read the list.

For other BCL types that do not yet implement an interface or do not have virtual members, you need to extract the interface yourself. However, you should keep an eye on Comforting abstractions .

+3
source

You can use two routes; First, as you say, create a wrapper for them and paste this. However, it depends on how you want to populate the state of the objects you are wrapping. This case is not what I personally did. Check out the Krzysztof Kozmic blog about dynamic parsers:

Dynamic parameters of Castle Windsor

Hope this helps

0
source

Source: https://habr.com/ru/post/1369131/


All Articles