c# - Using Profiles in Automapper to map the same types with different logic -
I am using Automapers in my ASP.NET MVC website to see my database objects to map MODEL objects. And I profiles multiple of the same type of map, but using another logic. I had the idea of reading this where he says:
The key part in fact is the automaker's configuration profile, you can do group configuration with the profile. Perhaps in a profile you outline the dates in the same way, in other profiles you form dates in some other way. I'm just using one profile.
So I have created a profile for one case:
Public category MyProfile: Profile {protected override string ProfileName {{Get "MyPropilations" Return ; }} Configure Secure Override Z () {CreateMap & lt; DateTime, String & gt; (). Convert & lt; StringFormatimeInternet Converter & gt; (); }} Public class stringframdatTemType converter: ITEP connor & lt; DateTime, String & gt; {Public string convert (datetime source) {return source. Toaster ("dd / mm / yyyy", culture info. Invertorial culture); }}
and another for another case:
Public class MyProfile2: Profile {Safe Override String ProfileName {get {return "MyProfile2"; }} Configure Secure Override Z () {CreateMap & lt; DateTime, String & gt; (). Convert & lt; Other stringformatetime converter & gt; (); }} Public class Other StringsframeDayType Converters: ITepe Connor & lt; DateTime, String & gt; {Public string convert (datetime source) {return source. Toastring ("mm - yyyy", culture info. Inventive culture); }}
However, give me Mapper.Map & lt; & Gt; ()
No surcharge can be given to specify a profile. I was also taken into account with any destiny on the configuration
object.
Last registered profile always takes priority
Is there a way to use profiles for this purpose?
The general configuration for profiles has been applied to a variety of maps, such as formatting. However, types of maps are still global, you are better off creating different configuration objects, and creating a separate mapping engine for each. Mapper classes have a static mask only on each of them, with some lifecycle management.
Comments
Post a Comment