add wiring

This commit is contained in:
Aaron Po
2026-08-03 01:11:07 -04:00
parent 7162244454
commit 76380d32c3
13 changed files with 94 additions and 59 deletions

View File

@@ -8,26 +8,29 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="idunno.Password.Generator" Version="1.0.1" /> <PackageReference Include="idunno.Password.Generator" Version="1.0.1"/>
<PackageReference Include="Konscious.Security.Cryptography.Argon2" Version="1.3.1" /> <PackageReference Include="Konscious.Security.Cryptography.Argon2" Version="1.3.1"/>
<PackageReference Include="Microsoft.Data.SqlClient" Version="7.0.2" /> <PackageReference Include="Microsoft.Data.SqlClient" Version="7.0.2"/>
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.9" /> <PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.9"/>
<PackageReference Include="dbup" Version="5.0.41" /> <PackageReference Include="dbup" Version="5.0.41"/>
<!-- <!--
remove this override once microsoft ships official fix to vulnerability remove this override once microsoft ships official fix to vulnerability
https: https:
--> -->
<PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="3.50.3" /> <PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="3.50.3"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Domain\Domain.Entities\Domain.Entities.csproj" /> <ProjectReference Include="..\..\Domain\Domain.Entities\Domain.Entities.csproj"/>
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Sql\Infrastructure.Sql.csproj"/>
<ProjectReference Include="..\..\Features\Features.Breweries\Features.Breweries.csproj"/>
<ProjectReference Include="..\..\Features\Features.Auth\Features.Auth.csproj"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<!-- Pipeline-generated seed data, copied to the output directory so it can be opened via <!-- Pipeline-generated seed data, copied to the output directory so it can be opened via
ConnectionStrings.SqliteConnectionString at runtime. --> ConnectionStrings.SqliteConnectionString at runtime. -->
<None Include="SeedData\seed.sqlite" CopyToOutputDirectory="PreserveNewest" /> <None CopyToOutputDirectory="PreserveNewest" Include="SeedData\seed.sqlite"/>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -4,25 +4,28 @@ namespace Database.Seed.DatabaseHelpers;
public class ConnectionStrings public class ConnectionStrings
{ {
public static string SqlServerConnectionString => GetSqlServerConnectionString();
public static string SqliteConnectionString => "Data Source=SeedData/seed.sqlite";
private static string GetSqlServerConnectionString() private static string GetSqlServerConnectionString()
{ {
string server = var server =
Environment.GetEnvironmentVariable("DB_SERVER") Environment.GetEnvironmentVariable("DB_SERVER")
?? throw new InvalidOperationException("DB_SERVER environment variable is not set"); ?? throw new InvalidOperationException("DB_SERVER environment variable is not set");
string dbName = var dbName =
Environment.GetEnvironmentVariable("DB_NAME") Environment.GetEnvironmentVariable("DB_NAME")
?? throw new InvalidOperationException("DB_NAME environment variable is not set"); ?? throw new InvalidOperationException("DB_NAME environment variable is not set");
string user = var user =
Environment.GetEnvironmentVariable("DB_USER") Environment.GetEnvironmentVariable("DB_USER")
?? throw new InvalidOperationException("DB_USER environment variable is not set"); ?? throw new InvalidOperationException("DB_USER environment variable is not set");
string password = var password =
Environment.GetEnvironmentVariable("DB_PASSWORD") Environment.GetEnvironmentVariable("DB_PASSWORD")
?? throw new InvalidOperationException("DB_PASSWORD environment variable is not set"); ?? throw new InvalidOperationException("DB_PASSWORD environment variable is not set");
string trustServerCertificate = var trustServerCertificate =
Environment.GetEnvironmentVariable("DB_TRUST_SERVER_CERTIFICATE") ?? "True"; Environment.GetEnvironmentVariable("DB_TRUST_SERVER_CERTIFICATE") ?? "True";
SqlConnectionStringBuilder builder = new() SqlConnectionStringBuilder builder = new()
@@ -32,12 +35,9 @@ public class ConnectionStrings
UserID = user, UserID = user,
Password = password, Password = password,
TrustServerCertificate = bool.Parse(trustServerCertificate), TrustServerCertificate = bool.Parse(trustServerCertificate),
Encrypt = true, Encrypt = true
}; };
return builder.ConnectionString; return builder.ConnectionString;
} }
public static string SqlServerConnectionString => GetSqlServerConnectionString();
public static string SqliteConnectionString => "Data Source=SeedData/seed.sqlite";
} }

View File

@@ -10,7 +10,7 @@ FROM build AS publish
ARG BUILD_CONFIGURATION=Release ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Database/Database.Seed/Database.Seed.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false RUN dotnet publish "./Database/Database.Seed/Database.Seed.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM mcr.microsoft.com/dotnet/runtime:10.0 AS final FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
WORKDIR /app WORKDIR /app
COPY --from=publish /app/publish . COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Database.Seed.dll"] ENTRYPOINT ["dotnet", "Database.Seed.dll"]

View File

@@ -1,7 +1,14 @@
using Database.Seed.DatabaseHelpers; using Database.Seed.DatabaseHelpers;
using Database.Seed.PipelineData; using Database.Seed.PipelineData;
using Database.Seed.Sqlite; using Database.Seed.Sqlite;
using Features.Auth.DependencyInjection;
using Features.Auth.Repository;
using Features.Breweries.DependencyInjection;
using Features.Breweries.Repository;
using Infrastructure.Sql;
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Database.Seed; namespace Database.Seed;
@@ -25,6 +32,28 @@ public class Program
return 1; return 1;
} }
ServiceCollection services = new();
services.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build());
services.AddSingleton<ISqlConnectionFactory, DefaultSqlConnectionFactory>();
services.AddFeaturesBreweries();
services.AddFeaturesAuth();
using ServiceProvider provider = services.BuildServiceProvider();
IBreweryRepository breweryRepository;
IAuthRepository authRepository;
try
{
breweryRepository = provider.GetRequiredService<IBreweryRepository>();
authRepository = provider.GetRequiredService<IAuthRepository>();
}
catch (InvalidOperationException ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Error configuring database connection: {ex.Message}");
Console.ResetColor();
return 1;
}
Console.ForegroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine( Console.WriteLine(
@@ -32,22 +61,23 @@ public class Program
); );
Console.ResetColor(); Console.ResetColor();
for (int i = 0; i < breweries.Count; i++) for (var i = 0; i < breweries.Count; i++)
{ {
BreweryRecord brewery = breweries[i]; BreweryRecord brewery = breweries[i];
Console.WriteLine($"{i + 1}:\t{brewery.Brewery.NameEn}\t({brewery.Address.City.CityName}, {brewery.Address.City.Country})"); Console.WriteLine(
$"{i + 1}:\t{brewery.Brewery.NameEn}\t({brewery.Address.City.CityName}, {brewery.Address.City.Country})");
} }
Console.ForegroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Loaded {users.Count} users."); Console.WriteLine($"Loaded {users.Count} users.");
Console.ResetColor(); Console.ResetColor();
for (int i = 0; i < users.Count; i++) for (var i = 0; i < users.Count; i++)
{ {
UserRecord user = users[i]; UserRecord user = users[i];
Console.WriteLine($"{i + 1}:\t{user.User.FirstName} {user.User.LastName}\t ({user.Email})"); Console.WriteLine($"{i + 1}:\t{user.User.FirstName} {user.User.LastName}\t ({user.Email})");
} }
return 0; return 0;
} }
} }

View File

@@ -40,13 +40,13 @@ public sealed class PipelineSeedDataReader
NameEn = reader.GetString(0), NameEn = reader.GetString(0),
DescriptionEn = reader.GetString(1), DescriptionEn = reader.GetString(1),
NameLocal = reader.GetString(2), NameLocal = reader.GetString(2),
DescriptionLocal = reader.GetString(3), DescriptionLocal = reader.GetString(3)
}, },
Address = new BreweryAddress Address = new BreweryAddress
{ {
City = cities[reader.GetInt64(4)], City = cities[reader.GetInt64(4)],
PostalCode = reader.GetString(5), PostalCode = reader.GetString(5)
}, }
} }
); );
@@ -83,15 +83,15 @@ public sealed class PipelineSeedDataReader
Gender = reader.GetString(2), Gender = reader.GetString(2),
Username = reader.GetString(3), Username = reader.GetString(3),
Bio = reader.GetString(4), Bio = reader.GetString(4),
ActivityWeight = (float)reader.GetDouble(5), ActivityWeight = (float)reader.GetDouble(5)
}, },
Email = reader.GetString(6), Email = reader.GetString(6),
DateOfBirth = reader.GetString(7), DateOfBirth = reader.GetString(7),
Address = new UserAddress Address = new UserAddress
{ {
City = cities[reader.GetInt64(8)], City = cities[reader.GetInt64(8)],
PostalCode = reader.GetString(9), PostalCode = reader.GetString(9)
}, }
} }
); );
@@ -123,13 +123,15 @@ public sealed class PipelineSeedDataReader
PostalCode = new PostalCodeSpec PostalCode = new PostalCodeSpec
{ {
CountryFormatRegex = reader.GetString(7), CountryFormatRegex = reader.GetString(7),
CityRegexes = DeserializeStringArray(reader.GetString(8)), CityRegexes = DeserializeStringArray(reader.GetString(8))
}, }
}; };
return cities; return cities;
} }
private static IReadOnlyList<string> DeserializeStringArray(string json) => private static IReadOnlyList<string> DeserializeStringArray(string json)
JsonSerializer.Deserialize<List<string>>(json) ?? []; {
return JsonSerializer.Deserialize<List<string>>(json) ?? [];
}
} }