Spring应用程序的各个方面的依赖注入? [英] Dependency Injection in every aspect of a spring app?

查看:131
本文介绍了Spring应用程序的各个方面的依赖注入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Spring作为一个Web框架,但是我需要一些帮助来了解DI。

I am taking a look into Spring as a web framework, however I am needing a bit of help getting my head around DI.

构造对象的概念在运行时容器中就是这样一个新概念。

The concept of objects getting constructed in the container on run time is such a new concept.

我只是想知道这将如何反映在一个大型应用程序中,我是否会有一些模块在做更多的工作高度耦合或是否应该在运行时初始化每个对象?

I am just wondering how this will reflect in a big application, would I have some modules doing work that are more highly coupled or should every object be initialised at runtime?

这对我来说似乎有点密集,我的意思是说例如我有一个CSV文件数据挖掘应用程序,它会删除每行数据 - 每行数据都封装在我自己的一个 CSVRow 对象中进行处理或其他任何事情。只要Excel文件可以上载到服务器,就会实例化这些对象。我不知道我需要创建多少?

It all seems a little intensive to me, I mean say for example I have a CSV file data mining application that removes the data per row - each rows data is encapsulated in one of my own CSVRow objects for processing or whatever. These objects are instantiated whenever an Excel file maybe uploaded to the server. I don't know how many I will need to create?

我似乎有点迷失,任何清晰度,概述或一些指导都会非常感激。

I seem to be getting a bit lost, any clarity, an overview or some guidance would be much appreciated.

提前致谢!

推荐答案

我会尽力把它只是:


  • 对具有逻辑的无状态类使用依赖注入(业务逻辑,持久性逻辑,前端逻辑)

  • 对价值对象使用 new

  • use dependency injection for stateless classes that have logic (business logic, persistence logic, front-end logic)
  • use new for value objects

这篇关于Spring应用程序的各个方面的依赖注入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆