Spring的核心技术室依赖注入,下面是依赖注入之属性注入的实现过程,牛刀小试,请看效果。

1、首先添加Spring.Web引用。本例中是使用分层思想来演示的,下面是项目的结构和UserModel类的内容,为了简单操作,只有一个Name属性

2、修改Web.Config文件,配置注入环境

    <configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
<!-- 支持在 web.config 中定义对象 -->
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>

添加Spring的SectionGroup

 <system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpModules>
<!-- Spring 提供的 Module -->
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>

添加HttpModule配置

 <httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
<!-- 取消 Spring.NET 对于 Web 服务的处理 -->
<!--<add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web"/>-->
<add verb="*" path="ContextMonitor.ashx" type="Spring.Web.Support.ContextMonitor, Spring.Web"/>
<add verb="*" path="*.ashx" type="Spring.Web.Support.DefaultHandlerFactory, Spring.Web"/>
</httpHandlers>

添加HttpHandler配置

    </configSections>
<spring>
<context>
<!---外部文件注入-->
<!--<resource uri="Configration.xml"/>-->
<!--<resource uri="config://spring/objects"/>-->
</context> <objects>
<!--id为自定义的id和下面要注入的页面property节点下的framework要保持一致,type为要注入的属性的所在类 -->
<object id="framework" type="Spring.Model.UserModel,Spring.Model">
<!--name为注入的属性,value为属性的值-->
<property name="Name" value="Spring.NET"/>
</object> <!--页面注入-->
<object type="~/Default.aspx">
<property name="UserModel" ref="framework"></property>
</object>
</objects>
</spring>

依赖注入配置

3、实现注入

    /// <summary>
/// 定义注入点
/// </summary>
public UserModel UserModel { set; get; } protected void Page_Load(object sender, EventArgs e)
{
if (this.UserModel != null)
{
Label1.Text = this.UserModel.Name;
}
}

实现注入

4、效果图

spring 属性注入的更多相关文章

  1. Spring 属性注入(一)JavaBean 内省机制在 BeanWrapper 中的应用

    Spring 属性注入(一)JavaBean 内省机制在 BeanWrapper 中的应用 Spring 系列目录(https://www.cnblogs.com/binarylei/p/101174 ...

  2. Spring 属性注入(二)BeanWrapper 结构

    Spring 属性注入(二)BeanWrapper 结构 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) BeanWrap ...

  3. Spring 属性注入(三)AbstractNestablePropertyAccessor

    Spring 属性注入(三)AbstractNestablePropertyAccessor Spring 系列目录(https://www.cnblogs.com/binarylei/p/10117 ...

  4. Spring 属性注入(四)属性键值对 - PropertyValue

    Spring 属性注入(四)属性键值对 - PropertyValue Spring 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) P ...

  5. Spring属性注入、构造方法注入、工厂注入以及注入参数(转)

    Spring 是一个开源框架. Spring 为简化企业级应用开发而生(对比EJB2.0来说). 使用 Spring 可以使简单的 JavaBean 实现以前只有 EJB 才能实现的功能.Spring ...

  6. 六 Spring属性注入的四种方式:set方法、构造方法、P名称空间、SPEL表达式

    Spring的属性注入: 构造方法的属性注入 set方法的属性注入

  7. spring属性注入

    1,set方法注入 (1)对于值类型的属性: 在对象中一定要有set方法 package com.songyan.demo1; import com.songyan.injection.Car; /* ...

  8. java spring属性注入

    一.创建对象时候,向类里面属性设置值:一般有三个方式 1) .有参构造, 2). set**** 3).接口注入 二. 在spring框架里面,支持前面两种方式: 1).有参构造方法  用constr ...

  9. spring属性注入DI

    spring setter方式注入: 注入对象属性: 前提: 在bean对应实体中有对应的setter方法. 基础代码: 在bean中有另一个bean属性的setter方法. package cn.i ...

随机推荐

  1. MySql常用命令总结

    转载:http://www.php100.com/html/webkaifa/database/Mysql/2009/0910/3288.html  1:使用SHOW语句找出在服务器上当前存在什么数据 ...

  2. python学习 第一天

    正式学习python第一天,网上找到了python教程,带练习题的,又装了ubuntu. 这是学习笔记: list[]: 可变,append/1,insert/2,pop/index? tuple() ...

  3. mysql 查询去重 distinct

    mysql 查询去重 distinct   待完善内容..

  4. 中國區的代理協議的韓國遊戲廠商PatiGames

    “與阿裏巴巴簽署旗下游戲「突突三國」在中國區的代理協議的韓國遊戲廠商PatiGames決定與阿裏巴巴終止合作.”相信這條前不久報導的新聞,很多人並不陌生,但這背後其實並不像表面那樣簡單.早在今年4月P ...

  5. CSS3的高级特性

    CSS3对响应式设计非常有用:使用CSS3替代图片,在有带宽限制的网页中可有效减少http请求(从而使网页加载更快),并可使网页更灵活.更容易维护. 在开发CSS3时,要记住添加相关的浏览器私有前缀以 ...

  6. .net core 1.0 中的asp.net identity 的基本使用 序言

    2016年6月底,微软发不了vs2015 up3,在这个版本中,微软做了一些改变,本人目前也尚在学习使用之中,现把学习和使用的心得写出来,错误之处请大家指正. 开发环境:vs2015 UP3   项目 ...

  7. 解决mysql数据库插入中文字段时出现??? 的问题

    1.检查并修改mysql的my.ini的配置文件   default-character-set=utf8 2.建立数据库是要指定字符集   create database mydb default ...

  8. 给Source Insight做个外挂系列之四--分析“Source Insight”

    外挂的目的就是将代码注入到其它进程中,所以必须要有目标进程才能完成注入,而所谓的目标进程通常是某软件的一部分或者是全部,所以要对目标程序有深入地了解.一般外挂都是针对某个应用程序开发的,其装载.运行都 ...

  9. static 使用要注意的地方

     protected static string headimg = string.Empty; 这里用到 static ,下面如果这样写    object himg = DBUtility.DbH ...

  10. 浅谈OC对象初始化的三种姿势

    一.普通程序猿普通程序员使用最常见路人姿势等场.普普通通,纯属陆仁辈. 陆仁贾写法: // view 1 UIView *v1 = [UIView alloc] initWithFrame:CGRec ...