Creating a Plug-In Architecture

7,713 views

Published on

Slides from my presentation, "Creating a Plug-In Architecture in .NET". Code is available as well at https://github.com/ondrejbalas/plugin-architecture

  • Hi Chris, are you still having trouble? If so, send me an email through my contact page at http://utdes.com/#contact Thanks.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • I browsed thru the code on github, where is the bootstrapper/composition root in the food business examples? Sorry I am not seeing it.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • I don't the bootstrapper in the Pizza examples
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Absolutely, The code is on my github here: https://github.com/ondrejbalas/plugin-architecture
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Would it be possible to get the source code from your talk?
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Creating a Plug-In Architecture

  1. 1. Creating a Plug-in Architecture in .NET ONDREJ BALAS @ONDREJBALAS WWW.ONDREJBALAS.COM ONDREJ@ONDREJBALAS.COM
  2. 2. ONDREJ BALAS Microsoft MVP in .NET Writer for Visual Studio Magazine Owner of UseTech Design (est. 2001) Building software that drives business W W W.OND REJBALAS.COM OND REJ@OND REJBALA S.COM @ OND REJBALAS
  3. 3. • An external piece of functionality that may be added to an existing system by abiding by a contract pre-defined by that system. Plug-in (my definition)
  4. 4. • Split work across natural boundaries • Incrementally create and deploy features • Deploy only new and updated modules • Don’t need source code for existing system
  5. 5. • Changes to contracts are difficult to manage • Increased development time for small projects
  6. 6. // Get input – “HELLO” string input = Console.ReadLine().ToUpper(); // "Encrypt" it string output = ""; foreach (char c in input) { byte b = (byte) c; output += (char)(b < 78 ? b + 13 : b - 13); } // Write output – “URYYB” Console.WriteLine(output);
  7. 7. Tightly Coupled Code
  8. 8. static void Main(string[] args) { // Get input string input = Console.ReadLine().ToUpper(); // "Encrypt" it Rot13 encryptionAlgorithm = new Rot13(); string output = encryptionAlgorithm.Encrypt(input); // Write output Console.WriteLine(output); } public class Rot13 { public string Encrypt(string input) { string output = ""; foreach (char c in input) { output += (char)(c < 78 ? c + 13 : c - 13); } return output; } }
  9. 9. static void Main(string[] args) { // Get input string input = Console.ReadLine().ToUpper(); // "Encrypt" it IEncryptionAlgorithm encryptionAlgorithm = new Rot13(); string output = encryptionAlgorithm.Encrypt(input); // Write output Console.WriteLine(output); } public class Rot13 : IEncryptionAlgorithm { public string Encrypt(string input) { string output = ""; foreach (char c in input) { output += (char)(c < 78 ? c + 13 : c - 13); } return output; } } public interface IEncryptionAlgorithm { string Encrypt(string input); }
  10. 10. Decoupled Code
  11. 11. • Single - Automatically choose one. • One of Many - Like Single, but give the user the choice. Think smart phone apps • Many Simultaneously – Using the composite pattern, many plug-ins are treated as one. Like browser plug-ins; they have the potential of overlapping
  12. 12. • Most IoC containers – Ninject (using ninject.extensions.conventions) – Castle.Windsor – Unity – StructureMap – MEF – Managed Extensibility Framework – MAF – Managed AddIn Framework – Many other IoC containers
  13. 13. Add Sales Tax to Calculation Toppings! More Toppings!
  14. 14. • Why not use config files? Config files are for changing the data/data source. Plug-in architecture is for dropping in functionality • Deciding where to put plug-in points
  15. 15. • Recovering from plug-in crashes • Dynamic loading and unloading at run time • Updating an application while it’s running
  16. 16. Thanks! ONDREJ BALAS @ONDREJBALAS WWW.ONDREJBALAS.COM ONDREJ@ONDREJBALAS.COM @ONDREJBALAS GITHUB.COM/ONDREJBALAS

×