简体   繁体   中英

Castle Windsor - registration by convention

I have a project that uses Castle Windsor for a DI container.

Initially it was a small project so I have been registering each class individually, however the project is now growing so I would like to register by convention, however I am finding documentation difficult to apply to my situation.

Without going into too much detail I have a project which contains the interfaces each one following a naming convention such as IUserService.cs or IBuildingService.cs .

I then have another project which contains the implementations sticking to a similar convention UserService.cs or BuildingSevice.cs

At the moment that required two separate calls to Kernel.Register .

I know it is possible to register by convention, I am just not familiar with the syntax - anyone able to offer some guidance?

I think what you are looking for is this:

container.Register(Classes.FromThisAssembly() 
    .WithService.DefaultInterfaces());

If the implementations don't sit in the same assembly as the registration code then use on of the other "FromAssembly" methods

Castle's documentation is quite good :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM