IoC with AutoMapper Profile using Autofac
        Posted  
        
            by DownChapel
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by DownChapel
        
        
        
        Published on 2010-03-08T18:17:23Z
        Indexed on 
            2010/03/08
            18:21 UTC
        
        
        Read the original article
        Hit count: 861
        
automapper
I have been using AutoMapper for some time now. I have a profile setup like so:
public class ViewModelAutoMapperConfiguration : Profile
    {
        protected override string ProfileName
        {
            get { return "ViewModel"; }
        }
        protected override void Configure()
        {
            AddFormatter<HtmlEncoderFormatter>();
            CreateMap<IUser, UserViewModel>();
        }
    }
I add this to the mapper using the following call:
Mapper.Initialize(x => x.AddProfile<ViewModelAutoMapperConfiguration>());
However, I now want to pass a dependency into the ViewModelAutoMapperConfiguration constructor using IoC. I am using Autofac. I have been reading through the article here: http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/05/11/automapper-and-ioc.aspx but I can't see how this would work with Profiles.
Any ideas? Thanks
© Stack Overflow or respective owner