Comments (3)
Stumbled across this issue myself. Using BuildAdapter()
does not use the injected service IMapper
. If you need to access services, you always need to use IMapper
.
Inject IMapper
in your class or pass it as parameter, then you can use await mapper.From(source).AdaptToTypeAsync<Destination>()
and it will work. Only then the MapContext has access to the services.
from mapster.
Thanks @Skyppid!
It seems like this is still an issue though, as the docs describe that BuildAdapter()
should work equally well.
from mapster.
Thanks @Skyppid! It seems like this is still an issue though, as the docs describe that
BuildAdapter()
should work equally well.
My assumption is since Mapster is not exclusively for ASP.Net that the docs relate to the general usage. Accessing DI in the async after-delegate is very specific to ASP.Net though and in this case you're right. The docs should be extended to supply that information for this context.
But it only makes sense that in a general scenario where you don't have DI you'd approach it like it is stated in the docs. Took me a while to figure out as well, but I guess this was never considered during the development of Async. In general the Async extension is quite a whacky workaround. It works but I'd say it's not a beautiful implementation.
At least I'm having serious issues with it when it comes to polymorphic DTOs...
from mapster.
Related Issues (20)
- Value overwritten by re-mapping
- Support NET. 8.0 - Mapster.Tool HOT 2
- Update Mapster.Core to target netstandard2.0
- PreserveReference is using the src PropertyName to set the Destination property.
- Mapster tool How to declare custom mapping.
- Mapster re-writing value when mapping resulting in wrong destination type HOT 3
- Adapt to IList<T> does not update the destination IList<T>
- How Map From A Method Like Update ?
- Struggling with mapping readonly ICollection property
- EFcore uses ProjectToType mapping errors
- Destination and source type mismatch does not seem to be validated
- How can I obtain the changed field values after mapping two entities?
- New object is created on destination instead of null when using Adapt<> HOT 2
- Mapper NOT mapping capitalized abbreviations to record property names
- Adapt/AdaptToType DOES NOT working with anonymous object that returned from method
- Mapping hierarchies not working
- Separate namespaces to avoid ambiguous references
- when leves proertiy is same name,its exception
- Mapping with constructor and default values for ignored properties? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mapster.