Skip to content
isaacabraham edited this page Apr 21, 2013 · 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("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<ICommand>("Foo");