MapsterMapper / MapsterMapper/Mapster

Mapping must be called using ServiceAdapter

Open
#704 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
5.2k
Forks
410
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Im getting the above error. I cant quite figure out what its supposed to mean.? Looking at this test, I assume that its an old errormessage, and its supposed to be ServiceMapper instead of ServiceAdapter?
However, I am already using the ServiceMapper like this:

services.AddSingleton<IMapper, ServiceMapper>();

I setup my mapping configuration like this:

TypeAdapterConfig<Course, InProgressCourseViewDTO>.NewConfig()
    .AfterMappingAsync(async (course, viewDto) =>
    {
        await Helpers.SetImageUrls(course, viewDto);
    });

public static async Task SetImageUrls(Course course, InProgressCourseViewDTO dto)
{
            var blobClient = MapContext.Current.GetService<IBlobClient>();
            var blobEntry = await blobClient.GetPublicBlobAsync(course.blobReference.EntryId);
            dto.Url = blobEntry?.Url ?? default;
}

and using it like this:

private async Task<InProgressCourseViewDTO> MapInProgress(Course course)
{
    var view = await course.BuildAdapter().AdaptToTypeAsync<InProgressCourseViewDTO>();
    return view;
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the referenced InjectionTest.cs test and trace the ServiceMapper registration against the BuildAdapter().AdaptToTypeAsync call. Reproduce the error using the snippets and inspect how MapContext.Current resolves services during AfterMappingAsync. Done means determining whether the message or setup is incorrect and documenting or covering the expected behavior with a focused test.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.