tags:

views:

281

answers:

1

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

A: 

Well, I found a way of doing it by using an overload of AddProfile. There is an overload that takes an instance of a profile, so I can resolve the instance before passing it into the AddProfile method.

DownChapel

related questions