Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing a plug-in/templating system c#
    text
    copied!<p>I have a fairly simple console app that monitors an exchange mailbox, picks particular emails out, and updates a couple of databases based on the contents.</p> <p>I would like to implement a couple of similar systems. While it would be very simple to duplicate this system, I am looking at a more sophisticated solution - mainly an intellectual exercise, a learning exercise.</p> <p>I would like to build a core application that pulls template information periodically from a DB; this information would tell the app that is has to monitor a given mailbox for emails with given characteristics at a particular interval. </p> <p>I envision creating a master template (assembly) with some virtual functions (pre-processing, process items, archive items, send notifications etc). In turn, I'd create any number of templates that implement the interfaces in the master template, but the functionality could differ wildly in each case, one may update a database, while the next might store something in a file system.</p> <p><em>My first question is whether this is a sensible implementation?</em></p> <p><em>My second question is how to dynamically reference each template, and how would I call the methods of these templates at the appropriate time?</em></p> <p>If I were to extend my Templates project, adding a new class for each new template required, I'd overcome the problem of dynamically referencing the templates. But if I wanted to keep them in separate assemblies.. Is there a way to just drop them into the project? Don't forget, the templates will be listed in a DB, so the app will be aware of them, but how to make use of them...</p> <p><strong>UPDATE</strong>: I've figured how I can dynamically reference each template class; it requires me to supply the <a href="http://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname.aspx" rel="nofollow">Assembly-Qualified Name</a> to <a href="http://msdn.microsoft.com/en-us/library/w3f99sx1.aspx" rel="nofollow">GetType</a>: I've tried to dynamically generate the template in the main app:</p> <pre><code>string aqn= "MasterTemplates.TestTemplate, TestTemplate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; MasterTemplate mt = (MasterTemplate)Activator.CreateInstance(Type.GetType(aqn)); </code></pre> <p>So if I keep updating my MasterTemplates project, adding in new classes as necessary, I can achieve what I am aiming for. <strong>However, how can I handle different template assemblies?</strong> </p> <p>In the meantime, I'm shortly going to look at DBM's suggestion of the Managed Extensibility Framework.</p> <p><strong>Conclusion:</strong> I don't have the time to fully investigate MEF; though it's overkill for my current needs, it looks extremely promising. And I haven't figured how to easily develop and use different assemblies for different templates - instead I am keeping all templates in one assembly, which I will have to recompile and up-date each time I require a new template. Not quite as sophisticated as the MEF alternative, but simpler and suited to my current needs.</p>
 

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