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