2011-08-25 2 views
0

MVC3에서 작동하는 플러그인 시스템에서 작동하고 있습니다. DLL은 ~/Plugin/디렉토리에 있습니다. 지금까지 모델과 컨트롤러가 호스트에 의해 발견되고 뷰가 DLL에 제대로 임베드되면서 모든 것이 잘 작동하고 있습니다. 유일한 문제는 뷰를 Razor 엔진으로 컴파일 할 수 없다는 것입니다.MVC3 플러그인 시스템

이 같은 스트림으로 요청 된 리소스를 반환 내가 VirtualFile과 VirtualPathProvider를 사용하는 뷰를 해결하기 위해
[assembly: PreApplicationStartMethod(typeof(Dashboard.PluginReader), "Initialize")] 
namespace Dashboard 
{ 
    public class PluginReader 
    { 
     public static void Initialize() 
     { 
      foreach (string plugin in Directory.GetFiles(HostingEnvironment.MapPath("~/Plugin"), "*.dll", SearchOption.AllDirectories)) 
      { 
       Assembly assembly = Assembly.LoadFile(plugin); 
       BuildManager.AddReferencedAssembly(assembly); 
      } 
     } 
    } 
} 

:

모델과 컨트롤러는이 같은 응용 프로그램의 초기화 단계에서 추가

class AssemblyResourceVirtualFile : VirtualFile 
{ 
    string path; 
    public AssemblyResourceVirtualFile(string virtualPath) 
     : base(virtualPath) 
    { 
     path = VirtualPathUtility.ToAppRelative(virtualPath); 
    } 
    public override System.IO.Stream Open() 
    { 
     // /~Plugin/path.of.dll/path.of.razor.view 
     string[] parts = path.Split('/'); 
     string assemblyName = parts[2]; 
     string resourceName = parts[3]; 

     string path = HostingEnvironment.MapPath("~/Plugin") + "/"+ assemblyName; 

     System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFile(path); 
     if (assembly != null) 
     { 
      Stream resourceStream = assembly.GetManifestResourceStream(resourceName); 
      return resourceStream; 
     } 
     return null; 
    } 
} 

Razor가 컴파일하면 ViewBag와 같은 참조를 찾을 수 없어 예외가 반환됩니다. 이 임베디드 리소스를 작동 시키거나 기존 플러그인 시스템을 알 수있는 방법에 대한 아이디어가있는 사람이 있습니까?

+0

FubuMVC를 사용해 본 것이 있습니까? Bottles라는 개념을 통해 새로운 것을 추가 할 수 있다는 목표를 가지고 있습니다. –

답변

0

대답에 매우 유용 보이는

방금 ​​어떻게 이런 플러그인은 다음과 같은 확인하려면 :

마지막으로 Application_Start()에 입력하십시오.

protected void Application_Start() 
    { 
     foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) 
     { 
      // As you can see, it checks if the assembly has plugin in it's name 
      // If you want something more solid, replace it at will 
      if (assembly.ManifestModule.Name.ToLower().Contains("plugin")) 
      { 
       BoC.Web.Mvc.PrecompiledViews.ApplicationPartRegistry.Register(assembly); 
      } 
     } 

     AreaRegistration.RegisterAllAreas(); 

     RegisterGlobalFilters(GlobalFilters.Filters); 
     RegisterRoutes(RouteTable.Routes); 
    }