-
Notifications
You must be signed in to change notification settings - Fork 3
Named mappings
Isaac Abraham edited this page Jan 26, 2016
·
8 revisions
If you are using multimaps, concrete types are by default registered into Unity with their FullName as the name of the registration e.g.
namespace SampleApplication
{
[Multimap]
interface IMyCommand { }
class BackupCommand : IMyCommand { }
// in bootstrapper
container.AutomapAssemblies ("SampleApplication");
// some time later we want to get back the backup command
var backupCommand = container.Resolve(typeof(ICommand), "SampleApplication.BackupCommand");
}
If you want more control over what name a type is registered into Unity as, you can you the [MapAs]
attribute e.g.
[Multimap] interface IMyCommand { }
[MapAs("Foo")] class BackupCommand : IMyCommand { }
// Fluent alternative
AutomapperConfig.Create()
.AndUseNamedMappingFor(typeof(BackupCommand), "Foo");
// in bootstrapper
container.AutomapAssemblies ("SampleApplication");
// some time later we want to get back the backup command
var backupCommand = container.Resolve(typeof(ICommand), "Foo");