一、开发环境

系统:win10

编译器:VS2013

二、涉及程序集

Spring.Core.dll 1.3.1

Common.Logging.dll

三、开发过程

1.项目结构

2.编写Mobile.cs

namespace SpringNetMethodDi
{
public abstract class Mobile
{
//可以是virtual
public abstract SendTool GetSendTool();
}
}

3.编写SendTool.cs

namespace SpringNetMethodDi
{
public class SendTool
{
public void WeChat()
{
Console.WriteLine("我是Kimisme,正在用微信发信息");
}
}
}

4.编写RealOp.cs

namespace SpringNetMethodDi
{
public class RealOp
{
public virtual string Buy(string goods)
{
return goods + "是昨天的剩下的";
}
}
}

5.编写SuperMarket.cs

namespace SpringNetMethodDi
{
public class SuperMarket : IMethodReplacer
{
public object Implement(object target, System.Reflection.MethodInfo method, object[] arguments)
{
string value = arguments[0].ToString();
return value + "是今天的面包";
}
}
}

6.编写Door.cs

namespace SpringNetMethodDi
{
public delegate string OpenHandler(string arg); public class Door
{
public event OpenHandler OpenTheDoor; public void OnOpen(string arg)
{ if (OpenTheDoor != null)
{
Console.WriteLine(OpenTheDoor(arg));
}
}
}
}

7.编写Men.cs

namespace SpringNetMethodDi
{
public class Men
{
public string OpenThisDoor(string arg)
{
return "参数是:" + arg;
}
}
}

8.编写App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler,Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler,Spring.Core"/>
</sectionGroup>
</configSections> <spring>
<context>
<resource uri="config://spring/objects"></resource>
</context>
<objects xmlns="http://www.springframework.net">
<!--01抽象方法注入-->
<object name="sendTool" type="SpringNetMethodDi.SendTool,SpringNetMethodDi"></object>
<object name="mobile" type="SpringNetMethodDi.Mobile,SpringNetMethodDi">
<lookup-method name="GetSendTool" object="sendTool"/>
</object>
<!--02替换方法-->
<object name="replaceValue" type="SpringNetMethodDi.SuperMarket,SpringNetMethodDi"></object>
<object name="realOp" type="SpringNetMethodDi.RealOp,SpringNetMethodDi">
<replaced-method name="Buy" replacer="replaceValue">
<arg-type match="String"/>
</replaced-method>
</object>
<!--03事件注入-->
<object id="door" type="SpringNetMethodDi.Door,SpringNetMethodDi"></object>
<object id="men" type="SpringNetMethodDi.Men,SpringNetMethodDi">
<listener event="OpenTheDoor" method="OpenThisDoor">
<ref object="door"/>
</listener>
</object> </objects>
</spring>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

9.控制台代码

namespace SpringNetMethodDi
{
class Program
{
static void Main(string[] args)
{
IApplicationContext context = ContextRegistry.GetContext();
Mobile mobile = context.GetObject("mobile") as Mobile;
mobile.GetSendTool().WeChat(); RealOp op = context.GetObject("realOp") as RealOp;
Console.WriteLine(op.Buy("面包")); Door door = context.GetObject("door") as Door;
door.OnOpen("Opening");
Console.ReadKey();
}
}
}

四、备注

今天又掉进坑了,具体什么坑看问题汇总

最新文章

  1. web 前端- 表格字段(文件大小)单位格式化算法
  2. 我对windows消息机制的理解(参考深入浅出MFC,欢迎批评指正!!)
  3. Empire C:Basic 3
  4. 使用NPOI导入导出标准的Excel
  5. 手工创建tomcat应用,以及实现js读取本地文件内容
  6. SVN学习安装总结
  7. 增强Web可用性,你需要避免的七大设计错误
  8. LeetCode(3) - Longest Substring Without Repeating Characters
  9. Mcafee两个Mac版本之间的区别
  10. 深入学习微框架:Spring Boot
  11. OPENWRT make defconfig错误之一
  12. HDU 5323 DFS
  13. React Native 系列(六) -- PropTypes
  14. android中Log类的封装
  15. label按钮和文字对齐
  16. HTML5调用手机摄像机、相册功能 &lt;input&gt;方法
  17. Java计算文件MD5值(支持大文件)
  18. 转:Redis 使用经验总结
  19. Pandas时间序列
  20. android studio jni调用入门

热门文章

  1. AtCoder Grand Contest 012 B Splatter Painting(记忆化搜索)
  2. list去重精简代码版
  3. oracle索引简单使用
  4. CentOS 7防火墙服务FirewallD指南
  5. SQLServer时间分段查询
  6. kvc VS kvo
  7. 经典面试题回答——学习Java基础的目的
  8. 图像处理之基础---yuv420及其rgb,bayer, yuv, RGB的相互转换详解
  9. Android学习笔记-tween动画之java实现
  10. java 和 Android Base64加密