Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,39 @@ public async Task using_service_location_with_one_service()

opts.Services.AddSingleton(new ColorContext("Red"));
});

await Execute(new CSP5());

CSP5User.Flag.ShouldBeOfType<RedFlag>();
}

[Fact]
public async Task service_location_flag_does_not_leak_to_subsequent_handlers()
{
IfWolverineIsConfiguredAs(opts =>
{
opts.IncludeType(typeof(CSP5User));
opts.IncludeType(typeof(CSP6User));
opts.CodeGeneration.AlwaysUseServiceLocationFor<IFlag>();

opts.Services.AddScoped<IGateway, Gateway>();
opts.Services.AddScoped<IFlag>(x =>
{
var context = x.GetRequiredService<ColorContext>();
return context.Color.EqualsIgnoreCase("red") ? new RedFlag() : new GreenFlag();
});

opts.Services.AddSingleton(new ColorContext("Red"));
});

// Execute first handler
await Execute(new CSP5());
CSP5User.Flag.ShouldBeOfType<RedFlag>();

// Execute second handler - should still work with constructor injection
await Execute(new CSP6());
CSP6User.Gateway.ShouldNotBeNull();
}
}

public class CSP3;
Expand Down Expand Up @@ -117,4 +145,23 @@ public record RedFlag : IFlag;
public record GreenFlag : IFlag;

public interface IGateway;
public class Gateway : IGateway;
public class Gateway : IGateway;

public record CSP6;

[WolverineIgnore]
public class CSP6User
{
private readonly IGateway _gateway;
public static IGateway? Gateway { get; set; }

public CSP6User(IGateway gateway)
{
_gateway = gateway;
}

public void Handle(CSP6 message)
{
Gateway = _gateway;
}
}
4 changes: 2 additions & 2 deletions src/Wolverine/Wolverine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<PackageId>WolverineFx</PackageId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JasperFx" Version="1.17.0" />
<PackageReference Include="JasperFx.Events" Version="1.17.0" />
<PackageReference Include="JasperFx" Version="1.17.1" />
<PackageReference Include="JasperFx.Events" Version="1.19.1" />
<PackageReference Include="JasperFx.RuntimeCompiler" Version="4.3.2" />
<PackageReference Include="NewId" Version="4.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down
Loading