Sub-directory look up with MEF

At my current job, I had to implement a Scheduling system for our banking clients. The requirement was for it to be pluggable, i.e. it should be able to pickup schedulable items/tasks that their developers or our support team would give it. It had to be secure, and it had to be able to handle long running tasks.

My solution for this was to use Quartz.NET as my Scheduling engine, which I encapsulated inside a windows Service. To access it, my web application would make calls to WCF service hosted inside the Windows Service, which used a UserNamePasswordValidator to prevent unauthorized access to the service. The remaining requirement to meet was that of the schedulable tasks. The solution: MEF.

What is MEF?

The Managed Extensibility Framework (MEF) is a composition layer for .NET that improves the flexibility, maintainability and testability of large applications. MEF can be used for third-party plugin extensibility, or it can bring the benefits of a loosely-coupled plugin-like architecture to regular applications. – Big Mike

MEF allows you to make component discoverable through the”Export” attribute, and allows you to load them up through the “Import” attribute. This removes the need for the ugly Assembly.Load

In my particular case, each exposed Schedulable task could be dependent on multiple DLLs. Keeping those DLLs in a single folder presented the risks of conflict in the assembly version, and also made up for a large and ugly folder. To solve it, I made the code look for subfolders within a specific directory to import the schedulable tasks. Also, because their developers and our support staff needed to be able to drop their DLL folders at any time without stopping the windows service, I added logic to listen to the file system using the FileSystemWatcher class.

Here’s the code:

I hope this helps!

Advertisements
Sub-directory look up with MEF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s