Go to the documentation of this file.00001 using System;
00002 using System.Reflection;
00003 using System.Security;
00004 using System.Web.Mvc;
00005 using N2.Engine;
00006 using N2.Engine.MediumTrust;
00007 using N2.Web.Mvc.Html;
00008
00009 namespace N2.Web.Mvc
00010 {
00014 public static class MvcEngine
00015 {
00020 public static IEngine Create()
00021 {
00022 IEngine engine = N2.Context.Initialize(false);
00023
00024 return MvcInitialize(engine);
00025 }
00026
00031 public static IEngine Create(IServiceContainer container)
00032 {
00033 IEngine engine = new ContentEngine(container, EventBroker.Instance, new ContainerConfigurer());
00034 N2.Context.Replace(engine);
00035 return MvcInitialize(engine);
00036 }
00037
00038 private static IEngine MvcInitialize(IEngine engine)
00039 {
00040 ControllerBuilder.Current.SetControllerFactory(engine.Resolve<IControllerFactory>());
00041
00042 return engine;
00043 }
00044 }
00045
00049 public static class MvcEngineExtensions
00050 {
00056 public static void RegisterControllers(this IEngine engine, Assembly assembly)
00057 {
00058 foreach (Type type in assembly.GetExportedTypes())
00059 if (IsController(type))
00060 engine.AddComponentLifeStyle(type.FullName.ToLower(), type, ComponentLifeStyle.Transient);
00061 }
00062
00063 private static bool IsController(Type type)
00064 {
00065 return type != null
00066 && !type.IsAbstract
00067 && typeof (IController).IsAssignableFrom(type);
00068 }
00069 }
00070 }