Skip to content

Commit

Permalink
Fix incorrect HttpContextAccessor lifetime (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawxy authored Jun 15, 2023
1 parent 52c4652 commit 5b7edb6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Alba.Testing/Alba.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageReference Include="NSubstitute" Version="4.4.0" />
<PackageReference Include="Shouldly" Version="4.1.0" />
<PackageReference Include="xunit" Version="2.4.2" />
Expand Down
2 changes: 1 addition & 1 deletion src/Alba/Alba.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Description>Supercharged integration testing for ASP.NET Core HTTP endpoints</Description>
<AssemblyTitle>Alba</AssemblyTitle>
<Version>7.4.0</Version>
<Version>7.4.1</Version>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<AssemblyName>Alba</AssemblyName>
<PackageId>Alba</PackageId>
Expand Down
12 changes: 6 additions & 6 deletions src/Alba/AlbaHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public AlbaHost(IHostBuilder builder, params IAlbaExtension[] extensions)
builder = builder
.ConfigureServices(_ =>
{
_.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
_.AddSingleton<IServer>(x => new TestServer(x));
_.AddHttpContextAccessor();
_.AddSingleton<IServer, TestServer>();
});

foreach (var extension in extensions) builder = extension.Configure(builder);
Expand Down Expand Up @@ -287,8 +287,8 @@ public static async Task<IAlbaHost> For(IHostBuilder builder, params IAlbaExtens
builder = builder
.ConfigureServices(_ =>
{
_.AddScoped<IHttpContextAccessor, HttpContextAccessor>();
_.AddSingleton<IServer>(x => new TestServer(x));
_.AddHttpContextAccessor();
_.AddSingleton<IServer, TestServer>();
});

foreach (var extension in extensions) builder = extension.Configure(builder);
Expand All @@ -313,8 +313,8 @@ public static async Task<IAlbaHost> For(IHostBuilder builder, params IAlbaExtens
public static async Task<IAlbaHost> For(WebApplicationBuilder builder, Action<WebApplication> configureRoutes,
params IAlbaExtension[] extensions)
{
builder.Services.AddScoped<IHttpContextAccessor, HttpContextAccessor>();
builder.Services.AddSingleton<IServer>(x => new TestServer(x));
builder.Services.AddHttpContextAccessor();
builder.WebHost.UseTestServer();

foreach (var extension in extensions)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitSamples/NUnitSamples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0" />
<PackageReference Include="coverlet.collector" Version="3.2.0">
Expand Down

0 comments on commit 5b7edb6

Please sign in to comment.