Code Monkey home page Code Monkey logo

pakchoi's People

Watchers

James Cloos avatar 凉快 avatar

pakchoi's Issues

Client 需要在代码中手动创建 BeanDefinition 读取器,并指定要解析的 xml 配置文件。

虽然现在「初始化 Bean 实例」和「初始化 Bean 实例的字段值」的过程都由 BeanFactory 完成,而且 Client 不需要「初始化 BeanDefinition 对象」,但 Client 还是得指定「初始化 BeanDefinition 对象」的方式。

解析完之后,读取器生成的 BeanDefinition 对象先存储在读取器内部,Client 还要取出再注册到 BeanFactory 中。

没有把「初始化 BeanDefinition 对象」这个过程从 Client 完全分离。

Client 需要在代码中手动创建 Bean 对应的 BeanDefinition对象。

开发人员不仅要初始化和管理大量 Bean 实例,还要再创建 BeanDefinition 对象手动注册到 BeanFactory 中,那不是增加工作量吗?而且这个 IoC 容器和 Map 没什么区别。

BeanFactoryTest

// 2. 注册 bean
BeanDefinition beanDefinition = new BeanDefinition(new HelloService());
beanFactory.registerBeanDefinition("helloService", beanDefinition);

无法初始化 Bean 内部的引用字段(无法设置 Bean 依赖的对象)。

Bean 内部可能会有引用类型字段,也就是依赖别的对象。如果要在「初始化 Bean 实例」的时候设置依赖对象,那么就有两个问题:

  1. 哪些 Bean 先初始化?其实就是依赖关系的问题。如果要设置依赖的对象,就需要先初始化依赖的 Bean。但是现在 BeanFactory 都是按 Client 手动注册的顺序来创建 Bean。总不可能让 Client 按照依赖关系来注册 BeanDefinition。除此之外还存在 「循环引用」 的问题。

  2. 假设上一个问题解决了,BeanFactory 如何给 Bean 实例设置依赖对象?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.