normalian blog

Let's talk about Microsoft Azure, ASP.NET and Java!

Controllerについて

MVCソースコードを眺めていたので備忘録。
「DefaultControllerFactoryTest.cs」ファイル内に以下のコードを発見。

    // BAD: type isn't public
    internal class NonPublicController : Controller {}

    // BAD: type doesn't end with 'Controller'
    public class MisspelledKontroller : Controller {}

    // BAD: type is abstract
    public abstract class AbstractController : Controller {}

    // BAD: type doesn't implement IController
    public class NonIControllerController {}

    // GOOD: 'Controller' suffix should be case-insensitive
    public class Goodcontroller : Controller {}

ユーザが作成するControllerには以下の制約がある様だ。

  • Controllerは public な必要が有る。
  • Controllerは クラス名前が "controller"(大文字・小文字は問わない)で終わる必要がある。
  • Controllerクラスを継承する必要がある。