c# - Inject dictionary using dependency injection -


i created function(dictionary) project:

private static dictionary<string, func<imessageprocessor>> strategyfactories = new dictionary<string, func<imessageprocessor>>()     {         { "t.2.12.0", new func<imessageprocessor>(() => new hvpvtparser()) },         { "t.3.03.0", new func<imessageprocessor>(() => new pvtparser()) },         { "unknown", new func<imessageprocessor>(() => new unknownparser()) }     }; 

as per requirement, want rid of new operator classes (hvpvtparser, pvtparser , unknownparser). can improve function through dependency injection? during research, found option inject dictionary. unable understand word 'inject'. can provide code sample achieve goal or guidelines solve problem.

typically "inject" sort of service implements interface. in case like:

public interface istrategyfactoryservice {     public dictionary<string, func<imessageprocessor>> factories {get;} } 

your class have constructor parameter (if data required class function) or property (if data helpful not required).

then create classes implement interface - real 1 "live" app , fake 1 testing.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -