Skip to content

Customisation through attributes

Isaac Abraham edited this page Jan 26, 2016 · 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 to see
  • Easy to identify customisations for a specific type
  • Easy to apply
  • Extremely lightweight

###Drawbacks

  • Customisations scattered throughout codebase so hard to identify all customisations in a single place
  • Application types "polluted" with / coupled to customisation attributes
  • Overuse on single types / methods can become difficult to read.