Skip to content

feat: add dependency injection - #37

Open
DerStimmler wants to merge 2 commits into
mainfrom
feat/dependency-injection
Open

feat: add dependency injection#37
DerStimmler wants to merge 2 commits into
mainfrom
feat/dependency-injection

Conversation

@DerStimmler

@DerStimmler DerStimmler commented Sep 13, 2026

Copy link
Copy Markdown
Member
  • Added dependency injection support for custom error mappers through IServiceResultErrorMapper.
  • Added configurable ProblemDetails creation through IResultProblemDetailsProvider.
  • Added generated DI registrations and HttpContext overloads.
  • Added analyzers and a code fix for mapper and provider configuration issues.
  • Refactored and reorganized the source generator.
  • Added unit, generator, and integration tests for the new behavior.
  • Updated the example project and README documentation.
  • Many code cleanups and refactorings

Important

All mapping methods - including the built-in ones for Result/Result<T> - are now provided by the integrated source generator. When upgrading from a version where they shipped as compiled library code, recompile the project: assemblies built against an older package version will miss these methods at runtime.

closes #36

@DerStimmler DerStimmler self-assigned this Sep 13, 2026
as ProblemHttpResult;

result!.StatusCode.Should().Be(400);
result.ProblemDetails.Title.Should().Be(TestHttpContextHelper.ProviderTitle);
var result = Result.Failure<string>("Error").ToAcceptedAtRouteHttpResult(http).Result as ProblemHttpResult;

result!.StatusCode.Should().Be(400);
result.ProblemDetails.Title.Should().Be(TestHttpContextHelper.ProviderTitle);
var result = Result.Failure<string>("Error").ToCreatedHttpResult(http).Result as ProblemHttpResult;

result!.StatusCode.Should().Be(400);
result.ProblemDetails.Title.Should().Be(TestHttpContextHelper.ProviderTitle);
var result = Result.Failure<string>("Error").ToCreatedAtRouteHttpResult(http).Result as ProblemHttpResult;

result!.StatusCode.Should().Be(400);
result.ProblemDetails.Title.Should().Be(TestHttpContextHelper.ProviderTitle);
var result = Result.Failure("Error").ToNoContentHttpResult(http).Result as ProblemHttpResult;

result!.StatusCode.Should().Be(400);
result.ProblemDetails.Title.Should().Be(TestHttpContextHelper.ProviderTitle);
var result = Result.Failure<string>("Error").ToJsonHttpResult(http).Result as ProblemHttpResult;

result!.StatusCode.Should().Be(400);
result.ProblemDetails.Title.Should().Be(TestHttpContextHelper.ProviderTitle);
var result = Result.Failure<string>("Error").ToNoContentHttpResult(http).Result as ProblemHttpResult;

result!.StatusCode.Should().Be(400);
result.ProblemDetails.Title.Should().Be(TestHttpContextHelper.ProviderTitle);
var result = Result.Failure<string>("Error").ToOkHttpResult(http).Result as ProblemHttpResult;

result!.StatusCode.Should().Be(400);
result.ProblemDetails.Title.Should().Be(TestHttpContextHelper.ProviderTitle);
.Result as ProblemHttpResult;

mapped!.ProblemDetails.Detail.Should().Be("failure");
mapped.ProblemDetails.Title.Should().Be("custom");
).Result as ProblemHttpResult;

mapped!.ProblemDetails.Detail.Should().Be("failure");
mapped.ProblemDetails.Title.Should().Be("custom");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use/Inject ProblemDetailsFactory for building ProblemDetails instances

1 participant