-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/abl-83-fix-warning-ef-singlequer…
…y' into abl-83-fix-warning-ef-singlequery
- Loading branch information
Showing
27 changed files
with
415 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
BuildingBlocks/src/BuildingBlocks.Infrastructure/BuildingBlocks.Infrastructure.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 13 additions & 12 deletions
25
...istence/BlobStorage/AzureStorageAccount/AzureStorageAccountServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.Persistence.BlobStorage; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Backbone.BuildingBlocks.Infrastructure.Persistence.BlobStorage.AzureStorageAccount; | ||
|
||
public static class AzureStorageAccountServiceCollectionExtensions | ||
{ | ||
public static void AddAzureStorageAccount(this IServiceCollection services, | ||
Action<AzureStorageAccountOptions> setupOptions) | ||
{ | ||
var options = new AzureStorageAccountOptions(); | ||
setupOptions.Invoke(options); | ||
|
||
services.AddAzureStorageAccount(options); | ||
} | ||
|
||
|
||
public static void AddAzureStorageAccount(this IServiceCollection services, AzureStorageAccountOptions options) | ||
{ | ||
services.Configure<AzureStorageAccountOptions>(opt => opt.ConnectionString = options.ConnectionString); | ||
services.AddSingleton<IOptions<AzureStorageAccountOptions>>(new OptionsWrapper<AzureStorageAccountOptions>(options)); | ||
services.Configure<AzureStorageAccountOptions>(opt => | ||
{ | ||
opt.ConnectionString = options.ConnectionString; | ||
opt.ContainerName = options.ContainerName; | ||
}); | ||
services.AddSingleton<AzureStorageAccountContainerClientFactory>(); | ||
services.AddScoped<IBlobStorage, AzureStorageAccount>(); | ||
} | ||
} | ||
|
||
public class AzureStorageAccountOptions | ||
{ | ||
public string ConnectionString { get; set; } = string.Empty; | ||
public required string ConnectionString { get; set; } | ||
|
||
[Required] | ||
[MinLength(2)] | ||
public required string ContainerName { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 9 additions & 33 deletions
42
...rsistence/BlobStorage/GoogleCloudStorage/GoogleCloudStorageServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,33 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.Persistence.BlobStorage; | ||
using Backbone.Tooling.Extensions; | ||
using Google.Apis.Auth.OAuth2; | ||
using Google.Cloud.Storage.V1; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Backbone.BuildingBlocks.Infrastructure.Persistence.BlobStorage.GoogleCloudStorage; | ||
|
||
public static class GoogleCloudStorageServiceCollectionExtensions | ||
{ | ||
public static void AddGoogleCloudStorage(this IServiceCollection services, | ||
Action<GoogleCloudStorageOptions> setupOptions) | ||
{ | ||
services.Configure(setupOptions); | ||
|
||
var options = new GoogleCloudStorageOptions(); | ||
setupOptions.Invoke(options); | ||
|
||
services.AddGoogleCloudStorage(options); | ||
} | ||
|
||
public static void AddGoogleCloudStorage(this IServiceCollection services, GoogleCloudStorageOptions options) | ||
{ | ||
services.AddSingleton(_ => | ||
{ | ||
var storageClient = options.GcpAuthJson.IsNullOrEmpty() | ||
var storageClient = options.ServiceAccountJson.IsNullOrEmpty() | ||
? StorageClient.Create() | ||
: StorageClient.Create(GoogleCredential.FromJson(options.GcpAuthJson)); | ||
: StorageClient.Create(GoogleCredential.FromJson(options.ServiceAccountJson)); | ||
return storageClient; | ||
}); | ||
|
||
services.AddScoped<IBlobStorage>(sp => | ||
{ | ||
var storageClient = sp.GetService<StorageClient>(); | ||
var logger = sp.GetService<ILogger<GoogleCloudStorage>>(); | ||
|
||
if (storageClient == null) | ||
{ | ||
throw new Exception("A StorageClient was not registered in the dependency container."); | ||
} | ||
|
||
if (logger == null) | ||
{ | ||
throw new Exception("A Logger was not registered in the dependency container."); | ||
} | ||
|
||
return new GoogleCloudStorage(storageClient, logger); | ||
}); | ||
services.AddScoped<IBlobStorage, GoogleCloudStorage>(); | ||
} | ||
} | ||
|
||
public class GoogleCloudStorageOptions | ||
{ | ||
public string? GcpAuthJson { get; set; } | ||
public string BucketName { get; set; } = string.Empty; | ||
public required string? ServiceAccountJson { get; set; } | ||
|
||
[Required] | ||
[MinLength(2)] | ||
public required string BucketName { get; set; } | ||
} |
Oops, something went wrong.