项目作者: zhyea

项目描述 :
极简的java ioc模拟
高级语言: Java
项目地址: git://github.com/zhyea/ash-framwork.git
创建时间: 2018-08-16T14:22:37Z
项目社区:https://github.com/zhyea/ash-framwork

开源协议:

下载


Ash Framework

一个极简的IOC框架。ash意为微尘,即微不足道。

此项目仅为练手而用。

示例代码

通过几段代码简单演示下ash-framework的使用。

创建一个Component类:

  1. package org.chobit.ash.test.compant;
  2. import org.chobit.ash.annotation.Component;
  3. @Component
  4. public class MyComponent {
  5. public String result() {
  6. return "The component result";
  7. }
  8. }

创建一个Service类, 在Service类中引用并注入了Component类的实例。:

  1. package org.chobit.ash.test.service;
  2. import org.chobit.ash.annotation.Autowired;
  3. import org.chobit.ash.annotation.Service;
  4. @Service
  5. public class MyService {
  6. @Autowired
  7. private MyComponent component;
  8. public String service() {
  9. System.out.println("This is a service!");
  10. return component.result();
  11. }
  12. }

创建场景类,实现注入并调用:

  1. package org.chobit.ash.test;
  2. import org.chobit.ash.boot.AshBootstrap;
  3. import org.chobit.ash.helper.BeanHelper;
  4. import org.chobit.ash.test.service.MyService;
  5. public class MyApp {
  6. public static void main(String[] args) {
  7. new AshBootstrap(MyApp.class).run();
  8. MyService myService = BeanHelper.getBean(MyService.class);
  9. System.out.println(myService.service());
  10. }
  11. }

执行结果如下:

  1. This is a service!
  2. The component result

能做的事情也就这样了。

其他

拖延好久写完以后,才意识到最早提出ioc创意的人也许是个极端的代码洁癖患者。

就这样。