|
-
Jan 18th, 2011, 03:36 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Automapper and ViewModels (destinations) with dependencies
Note: I just want to be clear that while I personally hate the idea of ViewModels having dependencies, this one is out of my hands. Actually it's worse. It's Viewmodels having a base class with a dependency. So your controller resolve that dependency, pass it to the ViewModel, which pass it to it's base class, without even using it. Out of my hands!
Using automapper to map domain and viewmodels (the latter designed as above).
So CreateMap<source, destination>(); won't work, since "destination" have a dependency that need to be supplied when constructing it (terrible, isn't it?)
I guess it would be something in the line of this ugly code:
Code:
var dependency = ObjectFactory.GetInstance<IWhatever>();
CreateMap<Source, Destination>().ConstructUsing(dest => new Destination(dependency));
Any advice here?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|