Approaches to use Repositories (w/ StructureMap) with AutoMapper?

Posted by jacko on Stack Overflow See other posts from Stack Overflow or by jacko
Published on 2010-03-29T11:19:17Z Indexed on 2010/03/29 11:23 UTC
Read the original article Hit count: 384

Filed under:
|
|
|
|

Any idea how I can tell AutoMapper to resolve a TypeConverter constructor argument using StructureMap?

ie. We have this:

    private class GuidToContentProviderConverter : TypeConverter<Guid, ContentProvider> {
        private readonly IContentProviderRepository _repository;

        public GuidToContentProviderConverter(IContentProviderRepository repository) {
            _repository = repository;
        }

        protected override ContentProvider ConvertCore(Guid contentProviderId) {
            return _repository.Get(contentProviderId);
        }
    }

And in the AutoMap registration:

        Mapper.CreateMap<Guid, ContentProvider>().ConstructUsing<GuidToContentProviderConverter>();

However, this generates a compile-time error about ctor args.

Any ideas? Or ideas to other approaches for using Automapper to hydrate domain objects from viewmodel ID's using a repository?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about automapper