Skip to content

Commit

Permalink
Add subcomponent to conn str
Browse files Browse the repository at this point in the history
  • Loading branch information
SapiensAnatis committed May 10, 2024
1 parent 4aac749 commit afa2205
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DragaliaAPI/DragaliaAPI.Database/ApiContextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ApiContext CreateDbContext(string[] args)
?.Get<PostgresOptions>();

DbContextOptions<ApiContext> contextOptions = new DbContextOptionsBuilder<ApiContext>()
.UseNpgsql(postgresOptions?.GetConnectionString())
.UseNpgsql(postgresOptions?.GetConnectionString("IDesignTimeDbContextFactory"))
.Options;

return new ApiContext(contextOptions, new StubPlayerIdentityService());
Expand Down
4 changes: 3 additions & 1 deletion DragaliaAPI/DragaliaAPI.Database/DatabaseConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ PostgresOptions postgresOptions
{
services = services
.AddDbContext<ApiContext>(options =>
options.UseNpgsql(postgresOptions.GetConnectionString()).EnableDetailedErrors()
options
.UseNpgsql(postgresOptions.GetConnectionString("ApiContext"))
.EnableDetailedErrors()
)
#pragma warning disable CS0618 // Type or member is obsolete
.AddScoped<IDeviceAccountRepository, DeviceAccountRepository>()
Expand Down
9 changes: 7 additions & 2 deletions DragaliaAPI/DragaliaAPI.Database/PostgresOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ public class PostgresOptions

public bool DisableAutoMigration { get; set; }

public string GetConnectionString()
/// <summary>
/// Gets a connection string for the current instance.
/// </summary>
/// <param name="subComponent">An optional suffix to add to the application name of the connection string.</param>
/// <returns>The connection string.</returns>
public string GetConnectionString(string subComponent)
{
NpgsqlConnectionStringBuilder connectionStringBuilder =
new()
Expand All @@ -27,7 +32,7 @@ public string GetConnectionString()
Password = this.Password,
Database = this.Database,
IncludeErrorDetail = true,
ApplicationName = "DragaliaAPI",
ApplicationName = $"DragaliaAPI_{subComponent}",
};

return connectionStringBuilder.ConnectionString;
Expand Down
2 changes: 1 addition & 1 deletion DragaliaAPI/DragaliaAPI/ServiceConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ PostgresOptions postgresOptions
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UsePostgreSqlStorage(pgCfg =>
pgCfg.UseNpgsqlConnection(postgresOptions.GetConnectionString())
pgCfg.UseNpgsqlConnection(postgresOptions.GetConnectionString("Hangfire"))
)
);

Expand Down

0 comments on commit afa2205

Please sign in to comment.