How to I make castle windsor automatically register controllers that don't have any dependencies?

StackOverflow https://stackoverflow.com/questions/1800820

  •  05-07-2019
  •  | 
  •  

Question

I know I can specify it in the configuration XML, but I'd like to not have to do so for every controller. For example: I have a controller without any dependencies being injected, but I'd rather not type out the XML component section in the config file or register it programmatically. Any ideas, suggestions, examples? Thanks for all the help!

Was it helpful?

Solution

This will automatically register all the controllers from the assembly of DependencyInjectionContainer class. No matter controllers have dependencies or not.

Register(
    AllTypes.Of<IController>()
        .FromAssembly(typeof(DependencyInjectionContainer).Assembly)
        .Configure(c => c.LifeStyle.Transient)
    );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top