Skip to content

Customisation through attributes

isaacabraham edited this page Dec 22, 2012 · 14 revisions

###Overview One of the two mechanisms for customisation of the Automapper is through decorating types with attributes, such as [Multimap], [Singleton] etc. etc. e.g.

         [Multimap, PolicyInjection]
         public interface ICommand { }
         [MapAs("Backup")
         class BackupCommand : ICommand { }
         [MapAs("Quit")
         class CloseApplicationCommand : ICommand { }

This registers two concretes to the ICommand interface, both with customised named mappings, whilst registering them to take part in policy injection.

###Benefits###

  • Declarative style is clear
  • Customisations live on their types so clear to see
  • Easy to apply

###Drawbacks

  • Customisations scattered throughout codebase
  • Application types "polluted" with / coupled to customisation attributes
Clone this wiki locally