3
我已經寫了叫RequestWrapper此類一個簡單的對象,它包含類型的一個方法:實施RequestWrapper此類REST風格的WCF服務
TResult WrapRequest<TResult>(Func<TResult> action)
它封裝了try..catch
任何行動,錯誤處理,日誌記錄,數據庫連接,事務(提交&回滾)等
目前我使用這樣的:(例如,不生產代碼)
return RequestWrapper.WrapRequest(() =>
{
Topic entity = GetRepository<Topic>().Find(uid);
if (entity == null)
throw new EntityNotFoundException("Topic not found.");
return new Topic
{
Name = entity.Name,
Posts = entity.Posts.Select(x => new Post
{
Body = x.Body,
}).ToList()
};
});
我只是環繞我的REST風格的Web服務的每個方法(使用WCF和WebHttpBinding)。
我的問題是:我應該如何實現自動執行包裝的行爲?這可能嗎?
好的和完整的解決方案,非常感謝。 :) – 2012-04-24 21:56:42