RetryPolicy in Subsonic
I am using Subsonic with a Sql开发者_如何转开发Azure database and it's working great. I would like to improve my application by implementing the suggested best practice mentioned in this blog article.
According to the article, I could do something like:
var sqlAzureRetryPolicy = ... code omitted ...;
return sqlAzureRetryPolicy.ExecuteAction<IEnumerable<Product>>(() =>
{
// Invoke a LINQ query.
return result;
});
However this would mean that I would have to copy and paste this code snippet all over my solution and I think it would be tedious and error prone, other members of my team could forget, etc. I don't think it's the best solution and I'm wondering if there's a better way.
Anybody has suggestions on how to do it?
Have you looked into implementing an extension method? You can "add" a method to existing classes (including IEnumerable and IQueryable in your case) to make it look like the method is part of the class. Extension methods can be useful to centralize this type of code. Here is a simple article showing how to extend the string class: http://www.developer.com/net/csharp/article.php/3592216/Using-the-New-Extension-Methods-Feature-in-C-30.htm
I personally use extension methods (I created a TryOpen and TryExecuteReader) to do just what you are asking for, but against SqlCommand and SqlConnection classes. So my code sample won't help you for LINQ.
精彩评论