8

I'm fairly decent with MVC3 and enjoy creating my sites with it, however, I am yet to think up and implement a decent method of a "plugin" system.

Basically, I aim to have a generic "blog-type" CMS which I can distribute across my sites, but with the option to have certain things as plugins.

For example:

Generic build:

  • User area
  • Basic blog/news editing

Plugins: (May be needed for one or two sites, but not all)

  • Chatroom plugin
  • Stats
  • and so on...

Currently I would just make it all and disable things through a config file, however it would be nice if i could just drop a folder into my FTP and have an MVC page which automatically picks it up!

I assume I would have to start with scanning the directory "/plugins" and picking up a "plugin.config" (Or similar) file which would contain the basic details.

But how would I get my main system to pick these things up and actually use them?!

JustAnotherDeveloper
  • 3,167
  • 11
  • 37
  • 68

4 Answers4

2

Try assembly scanning with StructureMap dependency injection.

Clive
  • 1,128
  • 2
  • 11
  • 19
2

You may be able to do this using MVC Areas, here are some links about them:

Community
  • 1
  • 1
Korich
  • 1,264
  • 1
  • 10
  • 14
1

Read this great tutorial: ASP.NET MVC2 Plugin Architecture Tutorial

It help me create a plugin architecture with MVC3.

artisonus
  • 76
  • 4
1

Areas solve the problem for you providing you have everything in the original project/assembly. You could write your plugin system to allow the plugins to register their own areas, or alternatively you could register some new view search paths in a custom Razor view engine.

I chose the latter for a recent OS project I wrote called Spruce, which uses a whole plugin architecture you might find useful as a reference.

You can scan all the assemblies in the bin directory on startup to check for plugins, via reflection. You usually check for types that implement an interface or inherit from a class, and use these along side an IoC container such as TinyIoc, NInject, StructureMap or Unity. I'd recommend TinyIoC which is used by NancyFX.

Chris S
  • 64,770
  • 52
  • 221
  • 239