automapper

ASP.NET MVC ViewModel mapping with custom formatting

て烟熏妆下的殇ゞ 提交于 2019-12-03 07:34:43
The project I'm working on has a large number of currency properties in the domain model and I'm needing for format these as $#,###.## for transmitting to and from the view. I've had a view thoughts as to different approaches which could be used. One approach could be to format the values explicitly inside the view, as in "Pattern 1" from Steve Michelotti : ...but this starts violating DRY principle very quickly. The preferred approach appears to be to do the formatting during the mapping between DomainModel and a ViewModel (as per ASP.NET MVC in Action section 4.4.1 and "Pattern 3" ). Using

Injecting AutoMapper dependencies using Ninject

左心房为你撑大大i 提交于 2019-12-03 07:08:43
I am having trouble injecting AutoMapper into an ASP.NET MVC 2 application using Ninject. I used Jimmy Bogard's post on AutoMapper and StructureMap type Configuration as a guide. public class AutoMapperModule : NinjectModule { public override void Load() { Bind<ITypeMapFactory>().To<TypeMapFactory>(); Bind<Configuration>().ToSelf().InSingletonScope().WithConstructorArgument("mapper", MapperRegistry.AllMappers); Bind<IConfiguration>().To<Configuration>(); Bind<IConfigurationProvider>().To<Configuration>(); Bind<IMappingEngine>().To<MappingEngine>(); } } Ninject throws an exception when

Configure AutoMapper to map to concrete types but allow Interfaces in the definition of my class

别等时光非礼了梦想. 提交于 2019-12-03 06:56:05
问题 I have some code that is similar to what is below. Basically it represents getting data from a web service and converting it into client side objects. void Main() { Mapper.CreateMap<SomethingFromWebService, Something>(); Mapper.CreateMap<HasSomethingFromWebService, HasSomething>(); // Service side var hasSomethingFromWeb = new HasSomethingFromWebService(); hasSomethingFromWeb.Something = new SomethingFromWebService { Name = "Whilly B. Goode" }; // Client Side HasSomething hasSomething=Mapper

Inject AutoMapper

喜欢而已 提交于 2019-12-03 06:50:06
I have been working on injecting AutoMapper into controllers. I like the implementation of Code Camp Server. It creates a wrapper around AutoMapper's IMappingEngine. The dependency injection is done using StructureMap. But I need to use Castle Windsor for my project. So, how do we implement the following dependency injection and set-up using Windsor? I am not looking for line-by-line equivalent implementation in Castle Windsor. If you want to do that, please feel free. Instead, what is Windsor equivalent of StructureMap's Registry and Profile? I need Profile to define CreateMap<> like the

Can Automapper map a paged list?

自闭症网瘾萝莉.ら 提交于 2019-12-03 06:38:42
问题 I'd like to map a paged list of business objects to a paged list of view model objects using something like this: var listViewModel = _mappingEngine.Map<IPagedList<RequestForQuote>, IPagedList<RequestForQuoteViewModel>>(requestForQuotes); The paged list implementation is similar to Rob Conery's implementation here: http://blog.wekeroad.com/2007/12/10/aspnet-mvc-pagedlistt/ How can you setup Automapper to do this? 回答1: AutoMapper does not support this out of the box, as it doesn't know about

AutoMapper Enum to byte with implemention IMapperConfigurator

感情迁移 提交于 2019-12-03 06:32:15
Enum definition is public enum RowStatusEnum { Modified = 1, Removed = 2, Added = 3 } public class RowStatusEnumConvertor : IMapperConfigurator { public void Cofigure() { Mapper.CreateMap<RowStatusEnum, byte>(); Mapper.CreateMap<byte, RowStatusEnum >(); } } I config autoMapper with Implemention IMapperConfigurator in RowStatusEnumConvertor class, but not work this code and not map this type, i think my config not correct or not enough, please help me thanks I have reproduced your problem. The solution is pretty simple, don't configure AutoMapper and set the base type of the enum to byte. Like

Automapper failing to map on IEnumerable

只愿长相守 提交于 2019-12-03 06:28:24
问题 I have two classes like so: public class SentEmailAttachment : ISentEmailAttachment { public SentEmailAttachment(); public string FileName { get; set; } public string ID { get; set; } public string SentEmailID { get; set; } public string StorageService { get; set; } public string StorageServiceFileID { get; set; } } And public class SentEmailAttachmentItem : ISentEmailAttachment { [ItemName] public string ID { get; set; } public string SentEmailID { get; set; } public string FileName { get;

Simple Convention Automapper for two-way Mapping (Entities to/from ViewModels)

好久不见. 提交于 2019-12-03 06:06:50
问题 UPDATE: this stuff has evolved into a nice project, see it at http://valueinjecter.codeplex.com check this out, I just wrote a simple automapper, it takes the value from the property with the same name and type of one object and puts it into another, and you can add exceptions (ifs, switch) for each type you may need so tell me what do you think about it ? I did it so I could do something like this: Product –> ProductDTO ProductDTO –> Product that's how it begun: I use the "object" type in my

How do I use AutoMapper with Ninject.Web.Mvc?

南笙酒味 提交于 2019-12-03 05:51:25
Setup I have an AutoMapperConfiguration static class that sets up the AutoMapper mappings: static class AutoMapperConfiguration() { internal static void SetupMappings() { Mapper.CreateMap<long, Category>.ConvertUsing<IdToEntityConverter<Category>>(); } } where IdToEntityConverter<T> is a custom ITypeConverter that looks like this: class IdToEntityConverter<T> : ITypeConverter<long, T> where T : Entity { private readonly IRepository _repo; public IdToEntityConverter(IRepository repo) { _repo = repo; } public T Convert(ResolutionContext context) { return _repo.GetSingle<T>(context.SourceValue);

How to configure Auto mapper in class library project?

扶醉桌前 提交于 2019-12-03 05:36:15
问题 I am using auto mapping first time. I am working on c# application and I want to use auto mapper. (I just want to know how to use it, so I don't have asp.net app neither MVC app.) I have three class library projects. I want to write transfer process in the service project. So I want to know how and where should I configure the Auto Mapper ? 回答1: You can place the configuration anywhere: public class AutoMapperConfiguration { public static void Configure() { Mapper.Initialize(x => { x