Search code examples
dependency-injectionsimple-injectorplugin-architecture

Building a plugin-based application with Simple Injector


I have been given the task to write a technical specification (and later implement) a system that will be build on a few sub-modules. The sub-modules will be developed partly in parallel so I would really like to avoid restarting the whole system each time a plugin is added or updated. Since I have already used Simple Injector in another project I plan to use it for IoC in each sub-module. Instead of introducing MEF (Managed Extensibility Framework) or MAF (Managed AddIn Framework) in the core binding the modules together, my plan is to see if Simple Injector can be used for handling the modules as well.

My plan is to use a FileSystemWatcher to watch a plugin directory and when a change is detected either have Simple Injector do it's thing or perhaps roll my own solution. I have read the discussion here but I believe my use case is different.

Requirements:

  • The core system runs as a Windows service and restarting this all the time should be avoided
  • Each module is responsible for internally orchestrating the work that needs to be done (which can be a lot, hence the requirement for not restarting everything)
  • The whole system is event-based. Modules will emit events to an event bus so that other modules can react (do it's thing) based on the event. Modules will, however, be allowed to do things on a regular basis as well. F.x. one module listens for new files in a directory, parses the file and puts data in a database. Other modules might need to do something based on this new data. Another module does some periodical calculations.
  • All modules will share a common interface IModule that will enable the core system to start and stop (dispose) the module, perhaps along with a method to register the event bus if I can't find another way around that
  • On system restart (f.x. server restart) the core should, of course, be able to pick up all existing modules

To be able to dynamically load/reload assemblies I plan on running each module in a separate AppDomain.

Is this possible using Simple Injector? Any other thoughts? Perhaps something I haven't thought about.


Solution

  • So, based on the correspondence with Steven I decided to look at alternatives and talk to my CTO. This resulted in a completely different architecture (microservices - probably implemented as Azure Functions) communicating through a message bus (Azure Service Bus). This complies with all the requirements and (using Azure Functions) ensures that we only pay for computing power when events arises that should be handled.