mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-21 00:08:05 +01:00
* Add WireMock.Net.AspNetCore.Middleware * . * WireMock.Net.Middleware.Tests * . * X-WireMock-Response-Delay
39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
// Copyright © WireMock.Net
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
using Stef.Validation;
|
|
using WireMock.Server;
|
|
|
|
namespace WireMock.Net.AspNetCore.Middleware;
|
|
|
|
/// <summary>
|
|
/// A <see cref="BackgroundService"/> used to start/stop the <see cref="WireMockServer"/>
|
|
/// </summary>
|
|
internal class WireMockBackgroundService : BackgroundService
|
|
{
|
|
private readonly WireMockServerInstance _serverInstance;
|
|
|
|
/// <summary>
|
|
/// Creates a new <see cref="BackgroundService"/> using an instance
|
|
/// of <see cref="WireMockServerInstance"/>
|
|
/// </summary>
|
|
/// <param name="serverInstance"></param>
|
|
public WireMockBackgroundService(WireMockServerInstance serverInstance)
|
|
{
|
|
_serverInstance = Guard.NotNull(serverInstance);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
_serverInstance.Start();
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
_serverInstance.Stop();
|
|
return base.StopAsync(cancellationToken);
|
|
}
|
|
} |