Web API, odata v4 and Castle Windsor

前端 未结 1 590
野的像风
野的像风 2021-01-24 22:37

I have WebApi project with ODataController and I\'m trying to inject some dependency into MyController. I was following this blogpost by Mark Seemann.

Consider code belo

相关标签:
1条回答
  • 2021-01-24 23:20

    Make sure you're registering all your controllers with the container:

    public class ControllerInstaller : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(Classes.FromThisAssembly().BasedOn<IController>().LifestylePerWebRequest())
                     .Register(Classes.FromThisAssembly().BasedOn<ApiController>().LifestylePerWebRequest());
        }
    }
    

    Windsor uses installers to encapsulate and partition registration logic. It also includes a helper called FromAssembly, so you don't need to manually instantiate all your installers:

    _container = new WindsorContainer();
    _container.Install(FromAssembly.This());
    
    0 讨论(0)
提交回复
热议问题