zoukankan      html  css  js  c++  java
  • Spring.NET

    • 使用
      • 引用

        • 如果直接引用dll的话,引用Spring.Core,Spring.Aop和Spring.Web即可
        • 添加nuget引用
      • IoC依赖注入功能

        • xml格式的一个或多个配置文件

          • 如service.xml或services.xml
          • 右键属性,将这个xml的输出目录(Copy to Output Directory)改为总是输出(Copy always)。
          • 代码中就会自动为接口注入指定的实例,该类中如果定义了同名的property,那么会将XML配置文件中property设置的value注入,类似于Java Spring的properties文件
           <?xml version="1.0" encoding="utf-8" ?>
           <objects>
             <object name="TestService" type="SpringNet.Service.TestClass,SpringNet.Service">
               <property name=“Xxx” value=“Yyy” />
            </object>
           </objects>
          
        • web.config中指定这些XML配置文件

          <!--spring.net 配置开始-->
          <configSections>
            <sectionGroup name="spring">
              < section  name ="context"  type ="Spring.Context.Support.WebContextHandler, Spring.Web" /> 
            </sectionGroup>
          </configSections>
          <spring>
            <context>
              <resource uri="file://~/Config/services.xml" />
            </context>
          </spring>
          <system.web>
            <httpHandlers>
              < add  verb ="*"  path ="*.aspx"  type ="Spring.Web.Support.PageHandlerFactory, Spring.Web" />
            </httpHandlers>
            <httpModules>
              < add  name ="Spring"  type ="Spring.Context.Support.WebSupportModule, Spring.Web" />
            </httpModules>
          </system.web>
           <!--spring.net 配置结束-->
        
        • 如果想要使用Spring.NET的MVC功能,那么还要将Global.asax.cs中的MvcApplication继承Spring.Web.Mac.SpringMvcApplication
      • IApplicationEventListener消息通知机制

        • 类似于qt的事件槽,.NET的MediatR组件
        • 过程
          • 定义一个集成自ApplicationEventArgs的自定义时间类,用于在发生事件时传递事件参数。
          • 消息接收/处理者,需要实现IApplicationEventListener接口,重写HandleApplicationEvent(object sender, ApplicationEventArgs e)方法,并在处理前先判断一下ApplicationEventArgs事件是否是自己负责处理的事件,避免处理了别人的事件。
          • 消息发送者,初始化自定义的ApplicationEventArgs事件参数,并发布事件:this._applicationContext.PublishEvent(this, customEventArg)。
  • 相关阅读:
    函数柯里化
    常用正则
    校验table行内的form编辑
    前端代码 读取excel表格数据
    cocos2d-x 帧动画学习
    Linux 下vim配置
    Android开发笔记 二
    cocos2d-x CCDictionary类学习
    Android开发笔记
    Cococs2d-x移植到Window下的问题
  • 原文地址:https://www.cnblogs.com/wyp1988/p/14859087.html
Copyright © 2011-2022 走看看