Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems like the main service could maintain a dictionary of plugins, indexed by name. Then for a client to see if the server provides a particular service, all the main service has to do is look up the name in the dictionary. And to process, the service just has to call a method on the object that's in the value portion of the dictionary entry. An example:</p> <p>You have three abstract classes: <code>Service</code>, <code>ServiceResult</code>, and <code>ServiceTask</code>. The contents of <code>ServiceTask</code> and <code>ServiceResult</code> aren't really important for this discussion. <code>Service</code> must have a parameterless constructor and a method called <code>Process</code> that takes a <code>ServiceTask</code> as its sole parameter. So your differential equation solver would look like:</p> <pre><code>public class DiffeqSolver : Service { public DiffeqSolver() { // do any required initialization here } public ServiceResult Process(ServiceTask task) { DiffeqTask dtask = task as DiffeqTask; if (dtask == null) { // Error. User didn't pass a DiffeqTask. // Somehow communicate error back to client. } // Here, solve the diff eq and return the result. } } </code></pre> <p>The main service is somehow notified of existing plugins. It maintains a dictionary:</p> <pre><code>Dictionary&lt;string, Service&gt; Services = new Dictionary&lt;string, Service&gt;(); </code></pre> <p>I assume you have some idea how you're going to load the plugins. What you want, in effect, is for the dictionary to contain:</p> <pre><code>Key = "DiffeqSolver", Value = new DiffeqSolver(); Key = "ServiceType1", Value = new ServiceType1(); etc., etc. </code></pre> <p>You can then have two methods for the main service: <code>ServiceIsSupported</code> and <code>Process</code>:</p> <pre><code>bool ServiceIsSupported(string serviceName) { return Services.ContainsKey(serviceName); } ServiceResult Process(string serviceName, ServiceTask task) { Service srv; if (Services.TryGetValue(serviceName, out srv)) { return srv.Process(task); } else { // The service isn't supported. // Return a failure result return FailedServiceResult; } } </code></pre> <p>I've simplified that to some extent. In particular, I'm using a <code>Dictionary</code>, which is not thread safe. You'd want to use a <code>ConcurrentDictionary</code>, or use locks to synchronize access to your dictionary.</p> <p>The more difficult part, I think, will be loading the plugins. But there are many available examples of creating a plugin architecture. I think you can find what you need.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload