What is the correct layer to configure your IoC container when using a service layer?

前端 未结 3 987
醉酒成梦
醉酒成梦 2021-01-19 06:11

I have a medium sized asp.net MVC app. It consumes a service layer that handles all the repository use, calling domain services, etc. My controller actions are very slim -

3条回答
  •  余生分开走
    2021-01-19 06:51

    I have the same situation as you and I tackle it as follows.

    The general rule I use is what ever has a global.asax or something similar, it needs to execute the code that registers the IoC components. Another way of putting it is that you need to run it one for each different process that is running (i.e. the website is in one process and the service is in another).

    In my case I do this once for the mvc website global.asax and again for the server. In this case the registrations that get made would be different between the service and the website.

    In addition I do one more thing. Due to the fact that I reuse components between the mvc app and the service (i.e. logging) I have a third core component that registers the core IoC components for the system and this component is called by the both the website and services registrations. Hence I anything that is common between the service and the website go into the core registration and then anything that is different goes into the 'interface' specific registration.

    Hope that helps.

提交回复
热议问题