This commit is contained in:
2026-03-18 18:48:01 +01:00
parent fcc1f563e5
commit e28532a1d9
4 changed files with 58 additions and 1 deletions
+6
View File
@@ -13,6 +13,12 @@
<PackageReference Include="MassTransit" Version="9.0.1" /> <PackageReference Include="MassTransit" Version="9.0.1" />
<PackageReference Include="MassTransit.RabbitMQ" Version="9.0.1" /> <PackageReference Include="MassTransit.RabbitMQ" Version="9.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.5" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="10.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.1" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.12" /> <PackageReference Include="SixLabors.ImageSharp" Version="3.1.12" />
</ItemGroup> </ItemGroup>
@@ -7,7 +7,33 @@ namespace Musify.Infrastructure.Messaging
{ {
public static class MassTransitDependencyInjection public static class MassTransitDependencyInjection
{ {
public static void AddMassTransitHandler(this IServiceCollection serviceDescriptors, IConfiguration configuration) public static void AddMassTransitClient(this IServiceCollection serviceDescriptors, IConfiguration configuration)
{
serviceDescriptors.AddMassTransit(options =>
{
options.UsingRabbitMq((busRegistrationContext, busFactoryConfigurator) =>
{
var section = configuration.GetSection("MassTransit");
var host = section["Host"]
?? throw new InvalidOperationException("MassTransit:Host configuration value not found.");
var username = section["Username"]
?? throw new InvalidOperationException("MassTransit:Username configuration value not found.");
var password = section["Password"]
?? throw new InvalidOperationException("MassTransit:Password configuration value not found.");
busFactoryConfigurator.Host(host, options =>
{
options.Username(username);
options.Password(password);
} );
} );
} );
}
public static void AddMassTransitConsumers(this IServiceCollection serviceDescriptors, IConfiguration configuration)
{ {
serviceDescriptors.AddMassTransit(options => serviceDescriptors.AddMassTransit(options =>
{ {
@@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
namespace Musify.Infrastructure.Persistence
{
public class DatabaseDesignTimeFactory : IDesignTimeDbContextFactory<Database>
{
public Database CreateDbContext(string[] args)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("AppSettings.json")
.Build();
var connectionString = configuration.GetConnectionString("Default");
var optionsBuilder = new DbContextOptionsBuilder<Database>();
optionsBuilder.UseNpgsql(connectionString);
return new Database(optionsBuilder.Options);
}
}
}
+2
View File
@@ -78,6 +78,7 @@ namespace Musify.Infrastructure.Storage
try try
{ {
await trasnsferUtility.UploadAsync(filePath, bucketName, fileName, cancellationToken); await trasnsferUtility.UploadAsync(filePath, bucketName, fileName, cancellationToken);
logger.LogInformation("Successfully transferred file {FileName} to S3 with bucket name {BucketName} and route {Route}", fileName, bucketName, route);
} }
catch catch
{ {
@@ -102,6 +103,7 @@ namespace Musify.Infrastructure.Storage
try try
{ {
var response = await amazonS3.PutObjectAsync(request, cancellationToken); var response = await amazonS3.PutObjectAsync(request, cancellationToken);
logger.LogInformation("Successfully uploaded file to S3 with bucket name {BucketName} and key name {KeyName}", bucketName, keyName);
} }
catch catch
{ {