Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialize RetryManager from EnterpriseLibraryContainer not working

I used this code to initialize RetryManager from Enterprise Library:

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.SqlAzure;
using Microsoft.Practices.TransientFaultHandling;

...

var manager = EnterpriseLibraryContainer.Current.GetInstance<RetryManager>();
return manager.GetDefaultSqlConnectionRetryPolicy();

Now I updated Enterprise Library NuGet package to the newest version and there is no EnterpriseLibraryContainer anymore.

How can I initialize the RetryManager with the new Enterprise Manager? It must be thread safe because my code is executed on web server.

like image 723
user1224129 Avatar asked Apr 28 '13 14:04

user1224129


1 Answers

I resolved it this way:

Remove all old NuGet packages and install only those two:

<package id="EnterpriseLibrary.TransientFaultHandling" version="6.0.1304.0" targetFramework="net45" />
<package id="EnterpriseLibrary.TransientFaultHandling.Data" version="6.0.1304.0" targetFramework="net45" />

Add this code once in application:

var strategy = new FixedInterval("fixed", 10, TimeSpan.FromSeconds(3));
var strategies = new List<RetryStrategy> {strategy};
var manager = new RetryManager(strategies, "fixed");
RetryManager.SetDefault(manager);

Then use new connection class from microsoft:

using (var connection = new ReliableSqlConnection(ConnectionString))
{
    connection.Open();
    ...
    command.ExecuteNonQueryWithRetry();
}

I also removed all configuration from Web.Config because it's in my code now.

like image 115
user1224129 Avatar answered Oct 13 '22 10:10

user1224129