Skip to content

Commit

Permalink
add string based EnableAttachments
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Nov 4, 2024
1 parent 8a52dae commit 60b5b0c
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/Attachments.Sql/SqlAttachmentsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ public static AttachmentSettings EnableAttachments(
throw new("This overload of EnableAttachments expects `Func<SqlConnection> connectionFactory` to return a un-opened SqlConnection.");
}

return EnableAttachments(configuration,
connectionFactory: async cancelaltion =>
return EnableAttachments(
configuration,
connectionFactory: async cancel =>
{
var connection = connectionFactory();
try
{
await connection.OpenAsync(cancelaltion);
await connection.OpenAsync(cancel);
return connection;
}
catch
Expand All @@ -43,6 +44,23 @@ public static AttachmentSettings EnableAttachments(
timeToKeep);
}

/// <summary>
/// Enable SQL attachments for this endpoint.
/// </summary>
public static AttachmentSettings EnableAttachments(
this EndpointConfiguration configuration,
string connection,
GetTimeToKeep? timeToKeep = null) =>
EnableAttachments(
configuration,
connectionFactory: async cancel =>
{
var sqlConnection = new SqlConnection(connection);
await sqlConnection.OpenAsync(cancel);
return sqlConnection;
},
timeToKeep);

/// <summary>
/// Enable SQL attachments for this endpoint.
/// </summary>
Expand All @@ -56,7 +74,10 @@ public static AttachmentSettings EnableAttachments(
return SetAttachments(configuration, settings, attachments);
}

static AttachmentSettings SetAttachments(EndpointConfiguration configuration, SettingsHolder settings, AttachmentSettings attachments)
static AttachmentSettings SetAttachments(
EndpointConfiguration configuration,
SettingsHolder settings,
AttachmentSettings attachments)
{
settings.Set(attachments);
configuration.EnableFeature<AttachmentFeature>();
Expand Down

0 comments on commit 60b5b0c

Please sign in to comment.