diff --git a/src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs b/src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs index fc4b463bd24..e2d22a4aedb 100644 --- a/src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs +++ b/src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs @@ -419,7 +419,7 @@ public static IResourceBuilder WithCreationScript(this ArgumentNullException.ThrowIfNull(builder); ArgumentNullException.ThrowIfNull(script); - builder.WithAnnotation(new CreationScriptAnnotation(script)); + builder.WithAnnotation(new PostgresCreateDatabaseScriptAnnotation(script)); return builder; } @@ -493,7 +493,7 @@ private static string WritePgAdminServerJson(IEnumerable private static async Task CreateDatabaseAsync(NpgsqlConnection npgsqlConnection, PostgresDatabaseResource npgsqlDatabase, IServiceProvider serviceProvider, CancellationToken cancellationToken) { - var scriptAnnotation = npgsqlDatabase.Annotations.OfType().LastOrDefault(); + var scriptAnnotation = npgsqlDatabase.Annotations.OfType().LastOrDefault(); try { diff --git a/src/Aspire.Hosting.PostgreSQL/PostgresCreateDatabaseScriptAnnotation.cs b/src/Aspire.Hosting.PostgreSQL/PostgresCreateDatabaseScriptAnnotation.cs new file mode 100644 index 00000000000..54e64354d71 --- /dev/null +++ b/src/Aspire.Hosting.PostgreSQL/PostgresCreateDatabaseScriptAnnotation.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Aspire.Hosting.ApplicationModel; + +namespace Aspire.Hosting.Postgres; + +/// +/// Represents an annotation for defining a script to create a database in PostgreSQL. +/// +internal sealed class PostgresCreateDatabaseScriptAnnotation : IResourceAnnotation +{ + /// + /// Initializes a new instance of the class. + /// + /// The script used to create the database. + public PostgresCreateDatabaseScriptAnnotation(string script) + { + ArgumentNullException.ThrowIfNull(script); + Script = script; + } + + /// + /// Gets the script used to create the database. + /// + public string Script { get; } +} diff --git a/src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs b/src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs index 977ea4c7cd3..a8271f79279 100644 --- a/src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs +++ b/src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs @@ -195,7 +195,7 @@ public static IResourceBuilder WithCreationScript(thi ArgumentNullException.ThrowIfNull(builder); ArgumentNullException.ThrowIfNull(script); - builder.WithAnnotation(new CreationScriptAnnotation(script)); + builder.WithAnnotation(new SqlServerCreateDatabaseScriptAnnotation(script)); return builder; } @@ -204,7 +204,7 @@ private static async Task CreateDatabaseAsync(SqlConnection sqlConnection, SqlSe { try { - var scriptAnnotation = sqlDatabase.Annotations.OfType().LastOrDefault(); + var scriptAnnotation = sqlDatabase.Annotations.OfType().LastOrDefault(); if (scriptAnnotation?.Script == null) { diff --git a/src/Aspire.Hosting.SqlServer/SqlServerCreateDatabaseScriptAnnotation.cs b/src/Aspire.Hosting.SqlServer/SqlServerCreateDatabaseScriptAnnotation.cs new file mode 100644 index 00000000000..7591d8fe97c --- /dev/null +++ b/src/Aspire.Hosting.SqlServer/SqlServerCreateDatabaseScriptAnnotation.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Aspire.Hosting.ApplicationModel; + +namespace Aspire.Hosting; + +/// +/// Represents an annotation for defining a script to create a database in SQL Server. +/// +internal sealed class SqlServerCreateDatabaseScriptAnnotation : IResourceAnnotation +{ + /// + /// Initializes a new instance of the class. + /// + /// The script used to create the database. + public SqlServerCreateDatabaseScriptAnnotation(string script) + { + ArgumentNullException.ThrowIfNull(script); + Script = script; + } + + /// + /// Gets the script used to create the database. + /// + public string Script { get; } +} diff --git a/src/Aspire.Hosting/ApplicationModel/CreationScriptAnnotation.cs b/src/Aspire.Hosting/ApplicationModel/CreationScriptAnnotation.cs deleted file mode 100644 index f66abcecf83..00000000000 --- a/src/Aspire.Hosting/ApplicationModel/CreationScriptAnnotation.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Aspire.Hosting.ApplicationModel; - -/// -/// Represents an annotation for defining a script to create a resource. -/// -public sealed class CreationScriptAnnotation : IResourceAnnotation -{ - /// - /// Initializes a new instance of the class. - /// - /// The script used to create the resource. - public CreationScriptAnnotation(string script) - { - ArgumentNullException.ThrowIfNull(script); - Script = script; - } - - /// - /// Gets the script used to create the resource. - /// - public string Script { get; } -}