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

前端 未结 3 989
醉酒成梦
醉酒成梦 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:49

    Coming from a Java perspective, I use the Spring framework for my IoC container. With it, the container really is application-wide. Although you can have different configuration files for different layers (a persistence config file, a services config file, a controller config file, etc), all of objects (beans in Java lingo) go into the container.

    I think this still ok though because there is no coupling between classes as you mentioned. A view does not need to know about a credit card processor, just because they are in the same IoC container. These classes will receive (by injection) only the dependencies they need, and are not concerned with other objects in the container.

提交回复
热议问题