c# - How to prevent Unity overwriting existing mappings with AutoRegistration -


unity 3 offers new capabilities autoregistration (registration convention) such as:

container.registertypes(     allclasses.fromloadedassemblies(),  //uses reflection     withmappings.frommatchinginterface, //matches interfaces implementations name     withname.default); 

this code register types implement named interfaces, against interfaces. example, class myservice : imyservice registered automatically though had written following:

container.registertype<imyservice, myservice >(); 

my question: if want of time, want choose different implementation 1 of interfaces, though named implementation exists?

see: patterns , practices on codeplex

an important article read explaining why want jeremy miller's convention on configuration article

what stops overriding automated mapping custom set loaded configuration (which - if empty - means no default mapping overridden):

 // have auto registration  container.registertypes(    allclasses.fromloadedassemblies(),  //uses reflection    withmappings.frommatchinginterface, //matches interfaces implementations name    withname.default);   // , override when necessary  container.loadconfiguration(); 

where configuration is

<?xml version="1.0" encoding="utf-8" ?> <unity xmlns="http://schemas.microsoft.com/practices/2010/unity"> <container>     <register type="imyservice" mapto="overriddenserviceimpl" /> </container> </unity> 

or

<?xml version="1.0" encoding="utf-8" ?> <unity xmlns="http://schemas.microsoft.com/practices/2010/unity"> <container>         ...nothing, not override defaults ... </container> </unity> 

moving optional configuration xml file has advantage - can reconfigure system without need recompile it.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -