-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π οΈ Refactoring on preparation for SSR App deployment
π Adding support for Azure Insights π Adding support for Key Vault π Adding support for Token Credential for Azure Services πΌ Updating dependencies
- Loading branch information
Showing
23 changed files
with
222 additions
and
110 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
6 changes: 0 additions & 6 deletions
6
src/AnimeFeedManager.Features/Infrastructure/Messaging/AzureBlobStorageOptions.cs
This file was deleted.
Oops, something went wrong.
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
17 changes: 17 additions & 0 deletions
17
src/AnimeFeedManager.Features/Infrastructure/Messaging/AzureStorageSettings.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
ο»Ώnamespace AnimeFeedManager.Features.Infrastructure.Messaging; | ||
|
||
public abstract record AzureStorageSettings; | ||
|
||
public sealed record ConnectionStringSettings(string StorageConnectionString) : AzureStorageSettings; | ||
|
||
public sealed record TokenCredentialSettings(QueueUri QueueUri, BlobUri BlobUri) : AzureStorageSettings; | ||
|
||
public readonly record struct QueueUri(Uri Uri) | ||
{ | ||
public static implicit operator Uri(QueueUri queueUri) => queueUri.Uri; | ||
} | ||
|
||
public readonly record struct BlobUri(Uri Uri) | ||
{ | ||
public static implicit operator Uri(BlobUri blobUri) => blobUri.Uri; | ||
} |
69 changes: 60 additions & 9 deletions
69
src/AnimeFeedManager.Features/Infrastructure/Registration.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,22 +1,73 @@ | ||
ο»Ώusing AnimeFeedManager.Features.Infrastructure.Messaging; | ||
ο»Ώusing System.Diagnostics.CodeAnalysis; | ||
using AnimeFeedManager.Features.Infrastructure.Messaging; | ||
using Azure.Identity; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace AnimeFeedManager.Features.Infrastructure; | ||
|
||
public static class InfrastructureRegistration | ||
{ | ||
public static IServiceCollection RegisterStorage(this IServiceCollection services, string connectionString) | ||
private const string TableBaseUrl = "https://{0}.table.core.windows.net"; | ||
private const string QueueBaseUrl = "https://{0}.queue.core.windows.net"; | ||
private const string BlobBaseUrl = "https://{0}.blob.core.windows.net"; | ||
|
||
|
||
public static IServiceCollection RegisterStorage(this IServiceCollection services, | ||
string connectionString) | ||
{ | ||
RegisterWithConnectionString(services, connectionString); | ||
services.RegisterCommonServices(); | ||
return services; | ||
} | ||
|
||
public static IServiceCollection RegisterStorage(this IServiceCollection services, | ||
IConfigurationManager configuration) | ||
{ | ||
|
||
services.Configure<AzureBlobStorageOptions>(options => | ||
var storageAccountName = configuration["StorageAccountName"]; | ||
if (!string.IsNullOrEmpty(storageAccountName)) | ||
{ | ||
options.StorageConnectionString = connectionString; | ||
}); | ||
RegisterWithAzureIdentity(services, storageAccountName); | ||
} | ||
else | ||
{ | ||
RegisterWithConnectionString(services, configuration.GetConnectionString("AzureStorage") ?? string.Empty); | ||
} | ||
|
||
services.RegisterCommonServices(); | ||
|
||
return services; | ||
} | ||
|
||
var tableClient = new TableServiceClient(connectionString); | ||
private static void RegisterCommonServices(this IServiceCollection services) | ||
{ | ||
services.TryAddSingleton<IDomainPostman, AzureQueueMessages>(); | ||
services.TryAddSingleton(typeof(ITableClientFactory<>), typeof(TableClientFactory<>)); | ||
services.TryAddSingleton(tableClient); | ||
} | ||
|
||
return services; | ||
private static void RegisterWithAzureIdentity(IServiceCollection services, string storageAccountName) | ||
{ | ||
if (CreateUri(TableBaseUrl, storageAccountName, out var tableUri) && | ||
CreateUri(QueueBaseUrl, storageAccountName, out var queueUri) && | ||
CreateUri(BlobBaseUrl, storageAccountName, out var blobUri)) | ||
{ | ||
services.TryAddSingleton<AzureStorageSettings>( | ||
new TokenCredentialSettings(new QueueUri(queueUri), new BlobUri(blobUri))); | ||
services.TryAddSingleton(new TableServiceClient(tableUri, new DefaultAzureCredential())); | ||
} | ||
else | ||
{ | ||
throw new ArgumentException("Azure Storage resources are malformed."); | ||
} | ||
} | ||
|
||
private static void RegisterWithConnectionString(IServiceCollection services, string connectionString) | ||
{ | ||
services.TryAddSingleton<AzureStorageSettings>(new ConnectionStringSettings(connectionString)); | ||
services.TryAddSingleton(new TableServiceClient(connectionString)); | ||
} | ||
|
||
private static bool CreateUri(string baseUrl, string storageAccountName, [NotNullWhen(true)] out Uri? tableUri) | ||
{ | ||
return Uri.TryCreate($"{baseUrl}{storageAccountName}", UriKind.Absolute, out tableUri); | ||
} | ||
} |
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: 1 addition & 2 deletions
3
src/AnimeFeedManager.Features/Seasons/IO/LatestSeasonsGetter.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
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
Oops, something went wrong.