what’s the recoomended approach in C# when one wants to implement a simple plugin approach?
So basically I have a processing loop that I want different behavior to occrur depending on what the user selected. Let’s say there are two places in the processing code for which logic (code)has to be different depending upon user input. For example the user may select either web based or file based upload. So I really kind of want to pass the two specific methods into the processing loop to represent
any suggestions re who to implement things for this here?
Thanks
Do you really need a (traditional) plugin based solution to this problem? Personally I do not think so, it sounds to me like are trying to over complicate the solution to what is really a simple problem.
The way I would approach this, would be to have a separate service class which is responsible for processing the logic depending on the type of upload. Have an enum to define what type of upload the user has selected, and then instantiate the relevant concrete implementation of the service class to do the processing.
public enum FileUploadType { File, Web } public interface IProcessingService { void Process(); object GetResults(); // or whatever you want to do with the results of processing } public void Process(FileUploadType fileUploadType) { IProcessingService service; switch(type) { case FileUploadType.File: service = new FileUploadProcessingService(); break; case FileUploadType.Web: service = new WebUploadProcessingService(); break; default: /* log error */ break; } service.Process(); /* do something with results of processing */ }You could then easily refactor this later on if you then decide you want to start using an IoC container, or introduce a proper plugin mechanism.