MapsterMapper / MapsterMapper/Mapster
Mapping must be called using ServiceAdapter
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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