Skip to content

Commit

Permalink
✨ Changed to async serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Marthijn van den Heuvel committed Feb 14, 2024
1 parent 3776338 commit 14383aa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Sitemap.AspNetCore/Sitemap.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Sitemap.Core" Version="1.0.1" />
<PackageReference Include="Sitemap.Core" Version="1.1.0" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions src/Sitemap.AspNetCore/SitemapResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,26 @@ public SitemapResult(SitemapIndex sitemapIndex)
/// <inheritdoc />
public override async Task ExecuteResultAsync(ActionContext context)
{
var xml = Serialize(context.HttpContext);
var xml = await SerializeAsync(context.HttpContext);

var response = context.HttpContext.Response;
response.ContentType = ContentType;
await response.WriteAsync(xml, Encoding.UTF8).ConfigureAwait(false);
await base.ExecuteResultAsync(context).ConfigureAwait(false);
}

private string Serialize(HttpContext httpContext)
private Task<string> SerializeAsync(HttpContext httpContext)
{
if (_sitemap != null)
{
var service = httpContext.RequestServices.GetRequiredService<ISitemapService>();
return service.Serialize(_sitemap);
return service.SerializeAsync(_sitemap);
}

if (_sitemapIndex != null)
{
var service = httpContext.RequestServices.GetRequiredService<ISitemapIndexService>();
return service.Serialize(_sitemapIndex);
return service.SerializeAsync(_sitemapIndex);
}

throw new InvalidOperationException("No sitemap or sitemap index provided.");
Expand Down

0 comments on commit 14383aa

Please sign in to comment.