-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update RouteTable with HTTP Endpoint bookmarks at application startup
Fixes #4405
- Loading branch information
1 parent
4a6872d
commit 0fb936e
Showing
4 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,5 @@ | |
<PackageReference Include="Open.Linq.AsyncExtensions" Version="1.2.0" /> | ||
</ItemGroup> | ||
|
||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/activities/Elsa.Activities.Http/StartupTasks/UpdateRouteTableStartupTask.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Elsa.Activities.Http.Bookmarks; | ||
using Elsa.Activities.Http.Contracts; | ||
using Elsa.Activities.Http.Extensions; | ||
using Elsa.Services; | ||
using Open.Linq.AsyncExtensions; | ||
|
||
namespace Elsa.Activities.Http.StartupTasks; | ||
|
||
/// <summary> | ||
/// A startup task that updates the route table with bookmarks. Triggers are already processed at startup. | ||
/// </summary> | ||
public class UpdateRouteTableWithBookmarks : IStartupTask | ||
{ | ||
private readonly IBookmarkFinder _bookmarkFinder; | ||
private readonly IRouteTable _routeTable; | ||
|
||
public UpdateRouteTableWithBookmarks(IBookmarkFinder bookmarkFinder, IRouteTable routeTable) | ||
{ | ||
_bookmarkFinder = bookmarkFinder; | ||
_routeTable = routeTable; | ||
} | ||
|
||
public int Order => 1000; | ||
|
||
public async Task ExecuteAsync(CancellationToken cancellationToken = default) | ||
{ | ||
// Find all HTTP endpoint bookmarks. | ||
var bookmarks = await _bookmarkFinder.FindBookmarksByTypeAsync<HttpEndpointBookmark>(cancellationToken: cancellationToken).ToList(); | ||
|
||
// Add them to the route table. | ||
_routeTable.AddRoutes(bookmarks); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters