JustAnotherDeveloper
JustAnotherDeveloper

Reputation: 3199

Plugin system with MVC3, Razor and C#

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:

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

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?!

Upvotes: 8

Views: 1390

Answers (4)

Chris S
Chris S

Reputation: 65466

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.

Upvotes: 1

artisonus
artisonus

Reputation: 76

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

It help me create a plugin architecture with MVC3.

Upvotes: 1

Clive
Clive

Reputation: 1138

Try assembly scanning with StructureMap dependency injection.

Upvotes: 2

Related Questions