Exemplo n.º 1
0
 /// <summary>
 /// Uses Azure Storage service as the store for distributed locking.
 /// </summary>
 /// <param name="options">The <see cref="WorkerHostOptions"/> used to configure locking and queue persistence.</param>
 /// <param name="configureAction">Configure the azure options.</param>
 /// <returns>The <see cref="WorkerHostOptions"/> used to configure locking and queue persistence.</returns>
 public static WorkerHostOptions UseAzureStorageLock(this WorkerHostOptions options, Action <LockManagerAzureOptions> configureAction = null)
 {
     options.Services.TryAddSingleton(typeof(ILockManager), serviceProvider => {
         var azureOptions = new LockManagerAzureOptions {
             StorageConnection = serviceProvider.GetService <IConfiguration>().GetConnectionString("StorageConnection"),
             EnvironmentName   = serviceProvider.GetService <IHostEnvironment>().EnvironmentName
         };
         configureAction?.Invoke(azureOptions);
         return(new LockManagerAzure(azureOptions));
     });
     return(options);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Registers an implementation of <see cref="ILockManager"/> that uses Microsoft Azure Blob Storage as a backing store.
 /// </summary>
 /// <param name="services">Specifies the contract for a collection of service descriptors.</param>
 /// <param name="configure">Configure the available options. Null to use defaults.</param>
 public static IServiceCollection AddLockManagerAzure(this IServiceCollection services, Action <IServiceProvider, LockManagerAzureOptions> configure = null)
 {
     services.AddTransient <ILockManager, LockManagerAzure>(serviceProvider => {
         var options = new LockManagerAzureOptions {
             ConnectionString = serviceProvider.GetRequiredService <IConfiguration>().GetConnectionString(LockManagerAzure.CONNECTION_STRING_NAME),
             EnvironmentName  = serviceProvider.GetRequiredService <IHostEnvironment>().EnvironmentName
         };
         configure?.Invoke(serviceProvider, options);
         return(new LockManagerAzure(options));
     });
     return(services);
 }