Code Sample

Create a new Mvc 3 application (or use an existing one). Create a reference to the MVCThemes assembly, add a reference to an IoC framework (we use Ninject), and you're good to go.

In Global.asax.cs (or Global.asax.vb) in the Application_Start method, add these lines:

			ViewEngines.Engines.Clear();
			ViewEngines.Engines.Add(new ThemeViewEngine());
Where ever you're configuring the IoC framework of your choice, remember to registrer/bind 2 interfaces, the IThemeProvider and the IThemeURLProvider interfaces. We have included 2 simple implementations (the QuerystringThemeProvider and SimpleThemeURLProvider providers), you can use these, or implement your own based on your own requirements.

	public class ThemeNinjectModule : NinjectModule {

		public override void Load() {
			Bind<IThemeProvider>().To<QuerystringThemeProvider>();
			Bind<IThemeURLProvider>().To<SimpleThemeURLProvider>();
		}
	}
Now you're ready to go, all you need is to mark your Controller classes with the Themed attribute.

 	[Themed]
	public class HomeController : Controller {

		public ActionResult Index() {
			return View();
		}
	}

Last edited Aug 3, 2012 at 10:54 AM by steentottrup, version 6

Comments

No comments yet.