What is need of AutoMapperStartupTask.cs and MappingExtensions.cs files...???

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
What is need of AutoMapperStartupTask.cs and MappingExtensions.cs files...???


Thank You...
12 years ago
Dharmik wrote:
What is need of AutoMapperStartupTask.cs and MappingExtensions.cs files...???


Thank You...


Hi Dharmik,

AutoMapperStartupTask initializes a library that will automatically map one object type to another object type. For example without AutoMapper a developer would need to write code like this:


Product p = new Product();
p.Id = 1;
p.Name = "Product One";

ProductModel model = new ProductModel();
model.Id = p.Id;
model.Name = p.Name;


Instead of typing all of that code a developer can simply use AutoMapper to do the mappings.



Product p = new Product();
p.Id = 1;
p.Name = "Product One";

ProductModel model = Mapper.Map<Product,ProductModel>(p);


The extensions create a fluent interface (using extension methods) for developers to call mapping logic. Instead of the last line of code in the sample above a developer can now write:


ProductModel model = p.ToModel();


Currently these classes are used mainly in the Administration applications and they are not used in every possible situation. I hope this helps clarify what they are for.

p.s. The startup task runs when the application starts and registers all the possible mappings that can take place.
12 years ago
@skyler.severns:

thanks for your great explanation.thank you so much.
but i'm little bit confused.
why dont you use in Nop.Web?

Thank You.
12 years ago
Dharmik wrote:
@skyler.severns:

thanks for your great explanation.thank you so much.
but i'm little bit confused.
why dont you use in Nop.Web?

Thank You.


You are welcome. There could be any number of reasons.

1. Automapper could have been implemented further into the rewrite of nopCommerce and preexisting models were not updated.
2. Much of the public model mapping is more complex than one property to another property. So the configuration for Automapper could be overwhelming and unclear.
3. It could be difficult to integrate Automapper with dependency injection, because of this it might be difficult to safely load data from services or repositories using Automapper.
12 years ago
skyler.severns wrote:
@skyler.severns:

thanks for your great explanation.thank you so much.
but i'm little bit confused.
why dont you use in Nop.Web?

Thank You.

You are welcome. There could be any number of reasons.

1. Automapper could have been implemented further into the rewrite of nopCommerce and preexisting models were not updated.
2. Much of the public model mapping is more complex than one property to another property. So the configuration for Automapper could be overwhelming and unclear.
3. It could be difficult to integrate Automapper with dependency injection, because of this it might be difficult to safely load data from services or repositories using Automapper.



Thank you so much.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.