I have some code that is using the Obsolete version of UseSqlServerInLeaseMode when adding a Rebus service to my app.
The obsolete version (below) has several parameters, all (but the last) of which are in use in my code.
public static void UseSqlServerInLeaseMode(
this StandardConfigurer<ITransport> configurer,
string connectionString,
string inputQueueName,
TimeSpan? leaseInterval = null,
TimeSpan? leaseTolerance = null,
bool automaticallyRenewLeases = false,
TimeSpan? leaseAutoRenewInterval = null,
Func<string> leasedByFactory = null,
bool enlistInAmbientTransaction = false,
bool ensureTablesAreCreated = true
)
The recommended version I should be using is:
public static SqlServerLeaseTransportOptions UseSqlServerInLeaseMode(
this StandardConfigurer<ITransport> configurer,
SqlServerLeaseTransportOptions transportOptions,
string inputQueueName
)
I'm really not clear how I should use this new version, most of the parameters in the new classes seem to be readonly and every variation I have tried so far will not compile.
Does someone have a code snippet showing how I remove this obsolete code?
Many thanks!
The trick is to use the various Set...
functions within SqlServerLeaseTransportOptions
So to convert from this:
x.UseSqlServerInLeaseMode(
connectionString,
inputQueueName,
leaseInterval,
leaseTolerance,
automaticallyRenewLeases,
leaseAutoRenewInterval,
leasedByFactory,
enlistInAmbientTransaction,
ensureTablesAreCreated,
)
It should look like this:
SqlServerLeaseTransportOptions transportOptions = new(connectionString, enlistInAmbientTransaction);
transportOptions.SetLeaseInterval(leaseInterval);
transportOptions.SetLeaseTolerance(leaseTolerance);
transportOptions.SetAutomaticLeaseRenewal(automaticallyRenewLeases, leaseAutoRenewInterval);
transportOptions.SetLeasedByFactory(leasedByFactory);
transportOptions.SetEnsureTablesAreCreated(ensureTablesAreCreated);
x.UseSqlServerInLeaseMode(
transportOptions,
inputQueueName
);