Approaches to use Repositories (w/ StructureMap) with AutoMapper?
- by jacko
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?