SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
ぜい肉のないコントローラ
   をめざそう!

            C
   ASP.NET MV
1.はじめに
目的
     ぜい肉のない美しいコントローラを、めざそう!


ASP.NET MVC

 ・関心の分離を推進するフレームワーク。

 ・MVCを選択したからといって、その心にそったコードが生
   まれるわけではない。

 ・特にコントローラの部分は、開発者の手によって様々な姿
 にかわる。
1.はじめに
対象者
  MVCのチュートリアルを終え、1~2回アプリを
  作成した方




         スピーカーについて
            MVCを1年ちょっと。
            TDD

            twitter : @miso_soup3
            blog : はてな miso_soup3
目次

 1. はじめに

 2. ぜい肉のないコントローラ の作り方

     3つのダイエット方法

 3. まとめ
2.ぜい肉のないコントローラの作り方
そもそもコントローラ(アクションメソッド)の仕事ってなあに?


1. 送信された入力データをうけとる

2. タスクを実行する

3. レスポンス用のビューモデルを準備する

4. ビューを呼び出す


              → この4つがコントローラの主な役割
2.ぜい肉のないコントローラの作り方
これは避けたい・・・メタボなコントローラの例
2.ぜい肉のないコントローラの作り方



 ダイエット その1

 モデルバインダー
 に任せる
2.ぜい肉のないコントローラの作り方
方法1 モデルバインダー
    コントローラの1つめの仕事である、
    「送信された入力データをうけとる」、
    これをモデルバインダーにお任せする。
2.ぜい肉のないコントローラの作り方
方法1 モデルバインダー
2.ぜい肉のないコントローラの作り方



 ダイエット その2

 アクションフィルター
 ・セレクタ属性で
 フォロー
2.ぜい肉のないコントローラの作り方
方法2 アクションフィルター・セレクタ属性
   メソッドに共通することは、アクション・セレクタ属性
   を作成し、メソッドから追い出そう、ということ。
2.ぜい肉のないコントローラの作り方
方法2 アクションフィルター・セレクタ属性
 [ AjaxOnly ]
2.ぜい肉のないコントローラの作り方
方法2 アクションフィルター・セレクタ属性
[ AllowGetJson ]
2.ぜい肉のないコントローラの作り方
方法2 アクションフィルター・セレクタ属性
 [ AcceptParameter ] [ NotAcceptParameter]
2.ぜい肉のないコントローラの作り方
方法2 アクションフィルター・セレクタ属性
 [ AcceptParameter ] [ NotAcceptParameter]
2.ぜい肉のないコントローラの作り方
方法2 アクションフィルター・セレクタ属性
2.ぜい肉のないコントローラの作り方
方法2 アクションフィルター・セレクタ属性

  OnActionExecuting




  OnActionExecuted

  OnResultExecuting
                      メソッドから追い出そう
  OnResultExecuted
2.ぜい肉のないコントローラの作り方



 ダイエット その3

 もう全部、
 外部に委託しちゃう
2.ぜい肉のないコントローラの作り方
方法3 タスクの実行を外部へ
       コントローラの仕事の1つである、
       「タスクの実行」、
       これを、他の人にお願いする。

                    Service...

 Controller         Repository...

                    Handller...
方法3 タスクの実行を外部へ
 気をつけたいこと
     2点
2.ぜい肉のないコントローラの作り方
方法3 タスクの実行を外部へ

気をつけたいこと      "依存性"

                 Service...

 Controller         Service...


                 Handller...
2.ぜい肉のないコントローラの作り方
方法3 タスクの実行を外部へ
気をつけたいこと
"1つのメソッドからは1つの外部コンポーネントを利用する"


 Controller          Service...
 アクションメソッド



                     Service...
 Controller
 Controller          Service...
 アクションメソッド
                     Service...
2.ぜい肉のないコントローラの作り方
 方法3 タスクの実行を外部へ
どのように解決しているか?
→サンプルを参考。

下の3つは、すべて違う方法で、コントローラの記述がされている。
(IoCフレームワーク:Unity, StructureMap, Autofac)

ASP.NET Design Patterns - ASP.NET MVC 2 Case Study Starter Kit
http://aspnetdesignpatterns.codeplex.com/

Project Silk
http://silk.codeplex.com/

EFMVC - ASP.NET MVC 4, Entity Framework 4.3 Code First and Windows Azure
http://efmvc.codeplex.com/
まとめ
3.まとめ


             モデルバインダーはここまで



共通する処理は、アクション・セレクタ属性へ



           → 外部へ
3.まとめ
3.まとめ

ダイエット方法

 1.   モデルバインダー
 2.   共通する処理は、アクション・セレクタ属性へ
 3.   外部に委託


紹介した3つの方法だけで、
とても品質のよいコントローラ を記述できる。


大事なのは、美しさを追い求めるこころです!!
ぜい肉のない美しいコントローラにした先には・・・
読みやすい、変更しやすい、など、
心地よい開発体験がまっています。

ここからは、想像になりますが・・・・

コントローラを極めると、
コードが宣言的なものだけになり、

コントローラの単体テストがいらなくなるのではないか?
もしくは、一発のコード自動生成で済むのではないか?

と思います。
コントローラの記述については、まだまだ考える必要
があると思います。

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

ぜい肉のないコントローラーをめざそう ASP.NET MVC