c# - Castle Windsor Register by Convention - how to register generic Repository based on Entity? -


this should general problem, i've searched couldn't found solution yet, if dupe, please point me appropriate link.

so, have generic repository support several entites, moment register bellow:

public class expensiveserviceinstaller : iwindsorinstaller { public void install(iwindsorcontainer container, iconfigurationstore store) { register<entitya>(container); register<entityb>(container); //etc etc //when there new 1 should register manually } void register<t>(iwindsorcontainer container) t : entity { container.register(component.for<irepository<t>>() .implementedby<repository<t>>() .lifestyle.transient); } } 

note:
repository located on repositories namespace
entities located on entities namespace, including entity baseclass of entities

it working fine, think should better way, more automatic way using registration convention, when add new entity on project, windsor automatically recognize it, , register repository it. , 1 more question, how ignore entity (the base class) not registered on container.

regards

you mean this?

container.register(component.for(typeof(irepository<>)) .implementedby(typeof(repository<>)) .lifestyle.transient); 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -