ASP.NET MVC 3 应用程序的扩展?

发布于 2024-10-24 18:00:03 字数 875 浏览 2 评论 0原文

我需要编写一个可扩展的 ASP.NET MVC 3 应用程序,而扩展是一个具有非常特定用途的.dll(即:论坛扩展、博客扩展、维基扩展等)。

不过,扩展程序不会有任何视图,这应该会使这个过程变得更加简单。它应该只有控制器和几个模型

我一直在考虑使用 MVC 区域来实现这一点,并像这样加载它们:

// Global.asax

public static void PreApplicationStartMethod()
{
    foreach (var file in Directory.GetFiles(
        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Extensions/"), "*.dll"))
    {
        BuildManager.AddReferencedAssembly(Assembly.LoadFile(file));
    }
}

protected void Application_Start()
{       
    AreaRegistration.RegisterAllAreas();
    ...
}

现在这工作得很好,但是,它看起来仍然是一种相当古老和静态的方式...... .NET 4 具有托管可扩展性框架。 MVC 3 具有依赖注入。

我读过有关便携式区域和 SharpArchitecture 的内容。我试图从源代码和文档中了解 Orchard 插件框架。但我仍然不确定我应该使用什么。

为了使我的问题更加实际 - 如何将外部项目中的控制器和模型包含到主 MVC Web 应用程序中?最好的方法是什么?我应该在这里使用依赖注入吗?

谢谢。

I need to write an extensible ASP.NET MVC 3 application, while an extension is a .dll with a very specific purpose (i.e: a forum extension, a blog extension, a wiki extension, etc).

An extension wouldn't have any views though, which should make this process much simpler. It should only has controllers and a few models.

I've been thinking about implementing this with MVC areas, and load them like so:

// Global.asax

public static void PreApplicationStartMethod()
{
    foreach (var file in Directory.GetFiles(
        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Extensions/"), "*.dll"))
    {
        BuildManager.AddReferencedAssembly(Assembly.LoadFile(file));
    }
}

protected void Application_Start()
{       
    AreaRegistration.RegisterAllAreas();
    ...
}

Now this worked perfectly, but still, it seems like a pretty old and static way... .NET 4 has Managed Extensibility Framework. MVC 3 has Dependency Injection.

I've read about Portable Areas and SharpArchitecture. I was trying to understand the Orchard plugin framework both from the source code and the documentation. But still I'm not sure what should I use.

To make my question more practical - how would you include Controllers and Models from an external project to the main MVC web application? What is the best way to do this? Should I use Dependency Injection here?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文