私はmvcを使用して、さまざまな統合用のフィードAPIを作成しています。たとえば、自分のサイトに投稿された質問のフィードを他の人に提供したいとします。最初の実装は、フィードコントローラーのアクションメソッドにパラメーターとしてサードパーティの名前を渡すことでした。
public XmlResult Get(string partner)
{
//Call the business layer and get the List<Questions>
if (!string.IsNullOrEmpty(partner))
{
partner = partner.ToLower();
switch (partner)
{
case "org1":
Org1XMLFeedViewModel org1FeedViewModel = new Org1XMLFeedViewModel();
org1FeedViewModel.LastBuildDate = DateTime.Now;
foreach (QuestionInfo Question in QuestionsForFeed)
{
Org1XMLFeedQuestionViewModel QuestionForFeed = new Org1XMLFeedQuestionViewModel(Question);
Org1FeedViewModel.Questions.Add(QuestionForFeed);
}
return new XmlResult(Org1FeedViewModel);
case "org2":
//similar to org1, use org2 ViewModel
default:
return new XmlResult(QuestionsForFeed);
}
}
return new XmlResult(QuestionsForFeed);
}
ただし、現在、異なるビューモデルを同じアクションメソッド内に含めるべきではないという考えがあります。したがって、パートナーをパラメーターとして渡す代わりに、パートナーごとに異なるアクションメソッドがあります。
どちらが優れているのか、そしてその理由は?それとも、頭に浮かぶより良いパターンはありますか?