inversion of control - Castle Windsor, overriding convention-registered components -


i started using castle windsor (3.3.0) first time , got stuck on convention based registration.

i register as possible name convention (idummyservice -> dummyservice):

var container = new windsorcontainer(); container.register(types.fromthisassembly().pick().withservicedefaultinterfaces()); container.register(component.for<idummyservice>().implementedby<dummyservice>().lifestylesingleton()); // long, i'm throwing here... 

... of course able change of registered components little bit (changing life time management, constructor parameters etc.)

because want keep registration simple be, avoid complex conditions. solution found simple - move custom stuff above name convention:

var container = new windsorcontainer(); container.register(component.for<idummyservice>().implementedby<dummyservice>().lifestylesingleton()); // custom stuff first... container.register(types.fromthisassembly().pick().withservicedefaultinterfaces()); // , convention @ end... 

my question now, right way how solve registration? can see castle windsor quite mighty in area , rather solve task properly, unfortunately don't see real-world examples.

one option custom configuration implementing icontributecomponentmodelconstruction interface - processmodel method called each component:

public class extraconfiguration : icontributecomponentmodelconstruction {     public void processmodel(ikernel kernel, componentmodel model)     {         if (model.implementation == typeof(dummyservice))         {             model.lifestyletype = lifestyletype.singleton;         }          if ...     } } 

you need register container prior registering other components:

container.kernel.componentmodelbuilder.addcontributor(new extraconfiguration()); 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -