MVCスタイルのルーティングのどこにでもある例は、次のようなものです。RouteTable.Routes RouteCollection?
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.Add(new Route
(
"Category/{action}/{categoryName}"
, new CategoryRouteHandler()
));
}
RouteTable.RoutesコレクションをRegisterRoutes()に渡す理由は何ですか?どうしてですか?
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
}
public static void RegisterRoutes()
{
RouteTable.Routes.Add(new Route
(
"Category/{action}/{categoryName}"
, new CategoryRouteHandler()
));
}
RouteTable.Routes以外のRouteCollectionはどのルートに追加されますか? RouteTable.Routes はWebアプリケーションの RouteCollectionですか?
Map()メソッドを持つ特定のIRouteHandlerがあります。
public class ChatRouteHandler : IRouteHandler
{
private static bool mapped;
public void Map()
{
if (!ChatRouteHandler.mapped)
{
RouteTable.Routes.Add
(
new Route("chat/{room}/{date}",
new ChatRouteHandler())
);
}
}
Map()がRouteCollectionを受け入れ、RouteTable.Routesコレクションに追加しない理由はありますか?もう一度、このIRouteHandlerに追加されるRouteCollectionは何ですか?
これがクラスデザインにどのように影響するかは間違いありません。 RouteCollectionやIRouteHandlerの単体テストの例やイラストをお勧めしますか?結局のところ、ユニットテストはRouteTable.Routesで見ることができませんでしたか? – core
Haackedにはルートのデモ用ユニットテストがあります。 http://haacked.com/archive/2007/12/17/testing-routes-in-asp.net-mvc.aspx 私の仕事では、同僚がRouteCollectionを派生して同様のことを行いました。 – CVertex
リンクをありがとう。感謝します。 Map()に関して、私は少し混乱しています。 MvcHandlerなどにMap()拡張メソッドがありますか?私はMVCが全く新しいです。 – core