为什么 OWIN 启动 类 声明为部分启动,但有时却不是?

Why are OWIN startup classes declared as partial, yet sometimes not?

如果我使用 VS2015.1 创建一个新的示例项目(WebForms 或 MVC),将创建两个用于配置 OWIN 的文件:

\Startup.cs(或.vb)

using Microsoft.Owin;
using Owin;

[assembly: OwinStartupAttribute(typeof(WebApplication6.Startup))]
namespace WebApplication6
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
    }
}

\App_Start\Config.Auth.cs(或.vb)

namespace WebApplication6
{
    public partial class Startup {

        public void ConfigureAuth(IAppBuilder app)
        {
           // removed for brevity
        }
    }
}

我看到 类 都被声明为 partial,但是在许多关于如何使用 OWIN 的在线示例中,类 不是 partial(请参阅here, here, here and here).

谁能解释一下是否有正确最佳方法,以及[=13]对应用程序有何不同=]用不?

我想我找到了答案 here,但仍然希望其他人可以在 OWIN 的上下文中特别添加任何内容:

The biggest use of partial classes is make life easier on code generators / designers. Partial classes allow the generator to simply emit the code they need to emit and do not have to deal with user edits to the file. Users are likewise free to annotate the class with new members by having a second partial class. This provides a very clean framework for separation of concerns.

所以部分class被简单地编译成class。部分声明允许具有相同名称的其他 classes 共存(然后将它们全部编译成一个 class)。

当且仅当每次构建发生时代码生成器都生成文件时,可接受的答案才是正确的。 OWIN 的示例不合格,因为在做出框架/脚手架选择时,两个文件仅生成一次。

因此,我可以看到启动是作为部分生成的唯一原因 class 是框架开发人员不想将 owin 授权(横切关注点)的生成与生成结合起来启动脚手架;然而,他们只成功地从基础 startup.cs 脚手架中移除了混乱并且无法解耦它,因为他们必须将 OwinStartupAttribute 引入基础启动并调用新部分中引入的方法class 配置验证。这实际上是如何不使用部分 class 的完美示例。部分 class 定义应该解耦,否则使用部分 class 所获得的好处会被它创建的间接性所抵消。必须修改基本部分 class 定义以添加另一个部分 class 以添加 OWIN 授权,这让我清楚地知道这是一种有缺陷的方法。