Poor-man’s runtime code patching? Trying to avoid Castle.DynamicProxy, Mono.Cecil, and the like.

I'm building a media tagging library. I want to be able to patch my code at runtime without recompiling in order to facilitate temporary updates until I can recompile the whole code base at a later time.

Here's another description of what I'm trying to do:

  1. Base program code is released.
  2. A bug is found in the existing code or a better way of doing something is found.
  3. A library containing patched/updated code specific to the issue (in other words, only relevant functions instead of entire classes) is built.
  4. This library is dropped in to the same location as the base program.
  5. When the base program runs, it executes the patched code from the drop in library where needed, and executes its own unpatched code where no patched library function exists.

I've mocked up an idea about how to do this:

  • Wrap all of my core program classes with prototypal inheritance via ProtoSharp
  • Use MEF to facilitate dependency injection and pass my wrapped core classes to objects loaded by MEF
  • MEF-loaded objects can now modify the core program objects as needed

I don't believe I need full on weaving for something this simple, and I don't think dynamically proxying objects is completely necessary, either. This is why I'm trying to avoid Castle.DynamicProxy and Mono.Cecil.

Does anyone have any suggestions? Does this sound like a reasonable solution?

by Nation_State_Tractor via /r/csharp

Leave a Reply