Asp.Net 熟悉 Spring
注:(为加强记忆,所以记录下来,对于有些地方为什么那样写,我也不太理解)
一、我们先创建个窗体应用程序Demos,事先熟悉它是这么实现的

第一步,先在项目的根目录下建一个library文件夹,目的是放我们的用到的dll文件。现在练习spring就要这三个就可以了:

第二步,添加这两个引用之后,新建一个配置文件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 uri="file://Service.xml"/>
</context>
<objects xmlns="http://www.springframework.net">
<!--<description>An example that demonstrates simple IoC features.</description>
<object name="UserInfo" type="SpringNetTest.UerInfoService, SpringNetTest">
<constructor-arg name="age" value="18"/>
<property name="Name" value="老马"/>
</object>-->
</objects>
</spring>
</configuration>
第三步, 创建一个userInfoService类和它的一个接口IUserInfoService
public class UerInfoService:IUserInfoService
{
public UerInfoService(int age)
{
Age = age;
}
public int Age { get; set; }
public string Name { get; set; }
public void Show()
{
Console.Write("我说ok,你说"+Name);
Console.WriteLine("构造函数参数注入 age"+Age);
}
}
第四步,在配置文件中加上自己的注入对象,也就是把上上图中的注释部分放开,也可以不在这个文件中添加,那就需要再创建一个xml文件,需要设置两个属相 “始终复制”,“嵌入到资源”
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<description>An example that demonstrates simple IoC features.</description>
<object name="UserInfo" type="SpringNetTest.UerInfoService, SpringNetTest">
<constructor-arg name="age" value="18"/>
<property name="Name" value="老马"/>
</object>
</objects>
第五步,准备工作做完,开始在form中测试我们的spring(将输出类型设置为控制台应用程序)
private void button1_Click(object sender, EventArgs e)
{
IApplicationContext ctx = ContextRegistry.GetContext(); //获取容器
IUserInfoService userInfoService =(IUserInfoService) ctx.GetObject("UserInfo"); //获取注入对象
userInfoService.Show();
}
Asp.Net 熟悉 Spring的更多相关文章
- [转]ASP.NET MVC Spring.NET NHibernate 整合
请注明转载地址:http://www.cnblogs.com/arhat 在整合这三个技术之前,首先得说明一下整合的步骤,俗话说汗要一口一口吃,事要一件一件做.同理这个三个技术也是.那么在整合之前,需 ...
- ASP.NET MVC Spring.NET NHibernate 整合
请注明转载地址:http://www.cnblogs.com/arhat 在整合这三个技术之前,首先得说明一下整合的步骤,俗话说汗要一口一口吃,事要一件一件做.同理这个三个技术也是.那么在整合之前,需 ...
- 一个小demo熟悉Spring Boot 和 thymeleaf 的基本使用
目录 介绍 零.项目素材 一. 创建 Spring Boot 项目 二.定制首页 1.修改 pom.xml 2.引入相应的本地 css.js 文件 3.编辑 login.html 4.处理对 logi ...
- ASP.NET MVC Spring.NET 整合
请注明转载地址:http://www.cnblogs.com/arhat 在整合这三个技术之前,首先得说明一下整合的步骤,俗话说汗要一口一口吃,事要一件一件做.同理这个三个技术也是.那么在整合之前,需 ...
- csharp: Configuring ASP.NET with Spring.NET and FluentNHibernate
Domain: FluentNhibernateLocalSessionFactoryObject.cs using System; using System.Collections.Generic; ...
- 说自己熟悉 Spring Cloud 这些面试题你会吗
问题一:什么是Spring Cloud? Spring cloud流应用程序启动器是基于Spring Boot的Spring集成应用程序,提供与外部系统的集成.Spring cloud Task,一个 ...
- Asp.Net mvc4 +Spring
添加相应的引用对象.(以下全部) 修改mvc的Global.asax文件内容 需要将控制器中原来需要new出来的对象改成属性成员 添加这个属性的注入对象 再去修改spring对web.config的一 ...
- 这些不知道,别说你熟悉 Spring
大家好,这篇文章跟大家来聊下 Spring 中提供的常用扩展点.Spring SPI 机制.以及 SpringBoot 自动装配原理,重点介绍下 Spring 基于这些扩展点怎么跟配置中心(Apoll ...
- Asp.net 面向接口可扩展框架之核心容器(含测试代码下载)
新框架的容器部分终于调通了!容器实在太重要了,所以有用了一个名词叫“核心容器”. 容器为什么那么重要呢?这个有必要好好说道说道. 1.首先我们从框架名称面向接口编程说起,什么是面向接口编程?(这个度娘 ...
随机推荐
- oracle报错注入的一些函数
oracle 报错注入 select dbms_xmltranslations.extractxliff((select banner from sys.v_$version where rownum ...
- 【第九篇】- Git 标签之Spring Cloud直播商城 b2b2c电子商务技术总结
Git 标签 如果你达到一个重要的阶段,并希望永远记住那个特别的提交快照,你可以使用 git tag 给它打上标签. 比如说,我们想为我们的 xxx 项目发布一个"1.0"版本. ...
- 找不到方法:“Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boolean)
找不到方法:"Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boo ...
- go命令帮助
Go is a tool for managing Go source code. go-->管理go源码的工具-->管理工具,包含很多功能命令 Usage: go <command ...
- 记录centos下nl与cat -n的不同
nl命令列出文件行不包含空格,cat -n包含空格 [root@bogon ~]# cat -n test.txt 1 a 2 aa 3 aaa 4 aaaa 5 aaaaa 6 7 aaaaaa [ ...
- mysql触发器实时检测一条语句进行备份删除
问题描述:用户有一个这样一个需求,在一张表里会不时出现 "违规" 字样的字段,需要在出现这个字段的时候,把整行的数据删掉.这是个采集任务,如果发现有"违规"字样 ...
- JAVA修饰符优先级先后顺序规范
在实际的开发中,会遇到定义静态常量时,有的人使用的修饰符顺序不一致,例如 ... static final ... 或者 ... final static ... 于是找到了下规范,分享下 优先级 修 ...
- Docker入门系列之一:什么是Docker?
原文作者:Jeff Hale 原文地址:https://towardsdatascience.com/learn-enough-docker-to-be-useful-b7ba70caeb4b 翻译: ...
- php去除html标签
function cutstr_html($string){ $string = strip_tags($string); $string = preg_replace(["\t" ...
- 阿里云短信功能php
1. 引入文件: https://help.aliyun.com/document_detail/53111.html?spm=a2c1g.8271268.10000.99.5a8ddf25gG0wW ...