Skip to content

Instantly share code, notes, and snippets.

@khalidabuhakmeh
Created March 11, 2014 13:13
Show Gist options
  • Select an option

  • Save khalidabuhakmeh/9485342 to your computer and use it in GitHub Desktop.

Select an option

Save khalidabuhakmeh/9485342 to your computer and use it in GitHub Desktop.
public class BusinessMappingTests
{
public BusinessMappingTests()
{
Mapper.Initialize(cfg => cfg.AddProfile<BusinessMappingProfile>());
Mapper.AssertConfigurationIsValid();
}
[Fact]
public void Can_map_editmodel_to_business()
{
var model = new EditModel {};
Mapper.Map<Business>(model);
}
[Fact]
public void Can_map_business_to_editmodel()
{
var business = new Business();
Mapper.Map<EditModel>(business);
}
}
@khalidabuhakmeh
Copy link
Author

I use StuctureMap to just pick up and register the profiles.

 public class Mapping : Registry
    {
        public Mapping()
        {
            Scan(x => {
                x.TheCallingAssembly();
                x.AddAllTypesOf<Profile>();
            });            
        }
    }

Then I load them on startup like this.

public static class MappingConfig
    {
        public static void Setup()
        {
            var profiles = DependencyResolver.Current.GetServices<Profile>();
            Mapper.Initialize(cfg => {
                foreach (var profile in profiles)
                    cfg.AddProfile(profile);
            });
        }
    }

Easy Peesy....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment