c# - How to replace factory pattern with dependency injection -


i have following situation: collection of objects have sent different third parties based on specific property of each object (the property defined enum). intend implement using factory pattern below.

can refactored use dependency injection instead?

public class servicea: ithirdparty {     public void send(ticket objecttobesent)     {         // call third party made send ticket     } }  public class serviceb: ithirdparty {     public void send(ticket objecttobesent)     {         // call third party made send ticket     } }  public interface ithirdparty {     void send(ticket objecttobesent); }  public static class thirdpartyfactory {     public static void sendincident(ticket objecttobesent)     {         ithirdparty thirdpartyservice = getthirdpartyservice(objecttobesent.thirdpartyid);         thirdpartyservice.send(objecttobesent);     }      private static ithirdparty getthirdpartyservice(thirdparty thirdparty)     {         switch (thirdparty)         {             case thirdparty.aaa:                 return new servicea();              default:                 return new serviceb();         }     } } 

yes can refactored - inject service sendincident, or class.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -