2018.4.16Spring.Net入门学习内容

三大方面:

IoC:Inversion of Control

控制翻转:就是创建对象的权利由开发人员自己控制New,转到了由容器来控制。

DI:Dependency Injection
It is a process whereby objects define their dependencies, that is, the other objects they work with, only through constructor arguments and properties that are set on the object instance after it is constructed. 
依赖注入:就是在通过容器来创建对象的时候,在对象的初始化是可以给一些属性、构造方法的参数等注入默认值(可以是复杂的类型.

Aop--权限校验--日志处理。Filter.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

开始配置VS:

1:引用System.Core 和 Common.Logging 两个服务引用

选4.0和发布版的

添加APP.config配置文件,代码如下:

 1 <?xml version="1.0" encoding="utf-8" ?>
 2 <configuration>
 3     <configSections>
 4         <sectionGroup name="spring">
 5             <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
 6             <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
 7         </sectionGroup>
 8     </configSections>
 9     <spring>
10         <context>
11             <resource uri="config://spring/objects"/>
12         </context>
13         <objects xmlns="http://www.springframework.net">
14             <object name="UserInfo"
15                     type="SpringNet.Userinfo,SpringNet">
16                 <property name="name"  value="刘军"/>
17                 <property name="book"  ref="BookInfo"/>
18             </object>
19             <object name="BookInfo"
20                 type="SpringNet.book,SpringNet">
21                 <property name="bookName"  value="三国演义"/>
22                 <property name="bookSal"  value="89"/>
23             </object>
24 
25 
26 
27         </objects>
28     </spring>
29 </configuration>
   <object name="UserInfo"
15                     type="SpringNet.Userinfo,SpringNet">
16                 <property name="name"  value="刘军"/>
17                 <property name="book"  ref="BookInfo"/>
18             </object>
   一个</object>代表一个类的声明,name代表名称,要和前面代码名称一样,type代表当前命名空间下的类,命名空间。
定义一个接口定义方法。

声明一个类实现该接口。返回的是配置文件中Value的值;

 
定义程序的主入口Main方法

运行效果如下:

当点击BUtton按钮时,返回输出格式字符串:值是配置文件中默认的值。

猜你喜欢

转载自www.cnblogs.com/FalseNull/p/8856002.html
今日推荐