Injecting AutoMapper profiles I'd like to know if I'm doing profile configuration in the wrong place or in the wrong way.

I'm following the Onion Architecture, so that restricts the direction of my dependencies towards the center.



Core

My domain model and AutoMapper facade:

namespace Core.Domain
{
    public class MyModel
    {
        // model stuff
    }
}

namespace Core.Services
{
    public interface IMapper
    {
        object Map(object source, Type sourceType, Type destinationType);
    }
}


Infrastructure

AutoMapper facade implementation:

namespace Infrastructure.Mapping
{
    public class Mapper : IMapper
    {
        private readonly IMappingEngine _mappingEngine;

        public Mapper(IMappingEngine mappingEngine)
        {
            _mappingEngine = mappingEngine;
        }

        public object Map(object source, Type sourceType, Type destinationType)
        {
            return _mappingEngine.Map(source, sourceType, destinationType);
        }
    }
}


UI

This is my controller and view model. I'm using the AutoMapper via a filter, following this example.

namespace UI.Controllers
{
    public class HomeController : Controller
    {    
        [AutoMap(typeof(MyModel), typeof(MyViewModel))]
        public ActionResult Index()
        {
            var myItem = _myRepository.GetById(0);
            return View(myItem);
        }
    }
}

namespace UI.ViewModels
{
    public class MyViewModel
    {
        // view stuff
    }
}


Dependency Resolution

This is where I have my doubts:

namespace DependencyResolution
{
    public class MappingModule : NinjectModule
    {
        public override void Load()
        {
            Mapper.Initialize(cfg =&gt; cfg.AddProfile(new MyProfile()));
            Bind&lt;IMappingEngine&gt;().ToMethod(ctx =&gt; Mapper.Engine);
            Bind&lt;IMapper&gt;().To&lt;Mapping.Mapper&gt;();

            Kernel.BindFilter&lt;AutoMapFilter&gt;(FilterScope.Controller, 0)
                  .WhenActionMethodHas&lt;AutoMapAttribute&gt;()
                  .WithConstructorArgumentFromActionAttribute&lt;AutoMapAttribute&gt;("sourceType", att =&gt; att.SourceType)
                  .WithConstructorArgumentFromActionAttribute&lt;AutoMapAttribute&gt;("destType", att =&gt; att.DestType);
        }
    }

    public class MyProfile : Profile
    {
        protected override void Configure()
        {
            Mapper.CreateMap&lt;MyModel, MyViewModel&gt;().ForMember(...);
        }
    }
}


Questions


Is the way I bind to AutoMapper wrong?  
Is this the wrong place for the profile (keep in mind the dependency restriction)?


In the ideal world I would have placed

Mapper.CreateMap&lt;MyModel, MyViewModel&gt;().ForMember(...)


in Global.asax, but how do I expose CreateMap without referencing AutoMapper?

Is there anything else you have noticed?
What is the purpose of the IMapper interface and Mapper class?  It looks to me that they are just wrapping the IMappingEngine interface and MappingEngine class.  While this is a good method when you have a third party class that doesn't have an interface, I think it is overkill here.  Why don't you just use the IMappingEngine where you need that functionality?

If you are going to keep your Mapper class, I would rename it, having two Mapper classes is confusing.

As for where it is, I don't have a problem with doing it this way.  All the wire-up is done in one place, and its easy to find and add to as needed.