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
Post a Comment