惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Securelist
V
V2EX
MongoDB | Blog
MongoDB | Blog
量子位
J
Java Code Geeks
GbyAI
GbyAI
Attack and Defense Labs
Attack and Defense Labs
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 叶小钗
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Cloudbric
Cloudbric
Recorded Future
Recorded Future
月光博客
月光博客
Help Net Security
Help Net Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
N
Netflix TechBlog - Medium
M
MIT News - Artificial intelligence
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
The Register - Security
The Register - Security
Scott Helme
Scott Helme
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
G
Google Developers Blog
T
Troy Hunt's Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
I
InfoQ
S
SegmentFault 最新的问题
G
GRAHAM CLULEY
C
Check Point Blog
Project Zero
Project Zero
有赞技术团队
有赞技术团队
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
P
Privacy International News Feed
AI
AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
F
Full Disclosure
C
CXSECURITY Database RSS Feed - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Hacker News: Front Page
S
Secure Thoughts
罗磊的独立博客
T
Threat Research - Cisco Blogs
aimingoo的专栏
aimingoo的专栏
博客园_首页
宝玉的分享
宝玉的分享
C
Cybersecurity and Infrastructure Security Agency CISA

博客园 - YFeng_Lee

webHttpBinding+wsHttpBinding+basicHttpBinding的区别 (转) AppDomain对于静态对象的独享引用 AppDomain 详解(转) .net工具 InstallShield12 添加自定义对话框,并根据输入值修改对应的Config文件。 普通管理类程序开发之难度系数、层次之说法(转自csdn) 待阅读书目 C#开发Windows Service程序 创建一个windows service应用程序 Ext简介(转) Ext的组件结构分析(转) XML与数据库 分析模式 - 责任模式 NHibernate Cascades: the different between all, all-delete-orphans and save-update 企业开发框架NHibernate和Spring.Net简介-3 企业开发框架NHibernate和Spring.Net简介-2 企业开发框架NHibernate和Spring.Net简介-1 Nhibernate学习之many-to-many篇(转 明了篇) Nhibernate学习起步之many-to-one篇(转 明了篇)
企业开发框架NHibernate和Spring.Net简介-4
YFeng_Lee · 2008-09-05 · via 博客园 - YFeng_Lee

(2)获得IApplicationContext应用。代码如下所示:

#001 using System;

#002 using System.Configuration;

#003 using Spring.Context;

#004 ...

#005 public static void Main ()

#006 { IApplicationContext ctx = ContextRegistry.GetContext();}

#007 ...

如上所述,using System.Configuratoin和using Spring.Context两条using语句被加到了MovieApp类文件中。其中,System.Configuration命名空间可以让应用程序存取保存在配置文件中的Spring.NET的IoC容器的定义;Spring.Context命名空间可以让应用程序存取IApplicationContext类,这个类是应用程序存取Spring.NET所提供的功能的主要方法。

方法main获得一个IApplicationContext的实现,它的配置信息已经被写在应用程序配置文件内名为<objects/>的节中。

(3)第一个对象的定义。到目前为止,在应用程序配置文件中还没有对象定义,所以下面定义一个对象。MovieLister实例的XML定义如下所示。

#001 ...

#002 <objects>

#003    <object name="MyMovieLister"

#004           type="Spring.Examples.MovieFinder.MovieLister, Spring.Examples.MovieFinder">

#005    </object>

#006 </object>

#007 ...

#003行:MyMovieLister是该对象的唯一标识符,使用这个标识符,这个对象的实例就能够被如下所示的代码中的IApplicationContext引用所获取。

#001 ...

#002 public static void Main ()

#003    { IApplicationContext ctx = ContextRegistry.GetContext();

#004      MovieLister lister = (MovieLister) ctx.GetObject ("MyMovieLister");}

#005 ...

lister实例仍然没有与IMovieFinder接口相应的实现注入。此时如果使用MoviesDirectedBy方法会导致NullReferenceException异常发生,因为lister实例仍然还没有对IMovieFinder的引用。注入到lister实例中的IMovieFinder接口实现的XML配置定义如下。

#001 ...

#002     <objects>

#003        ...

#004        <object name="MyMovieFinder"

#005       type="Spring.Examples.MovieFinder.SimpleMovieFinder, Spring.Examples.MovieFinder"/>

#006        </object>

#007         ...

#008     </object>

#009 ...

(4)设值注入。下面要做的是把以MyMovieFinder为标识符的IMovieFinder实例注入到以MyMovieLister为标识符的MovieLister实例中。这个注入动作使用设值注入的方法,代码如下所示:

#001 ...

#002 <objects>

#003 <object name="MyMovieLister"

#004 type="Spring.Examples.MovieFinder.MovieLister, Spring.Examples.MovieFinder">

#005 <!-- using setter injection... -->

#006 <property name="movieFinder" ref="MyMovieFinder"/>

#007 </object>

#008 <object name="MyMovieFinder"

#009 type="Spring.Examples.MovieFinder.SimpleMovieFinder, Spring.Examples.MovieFinder"/>

#010 </object>

#011 </objects>

#012 ...

当IApplicationContext接口取得了MyMovieLister对象以后,Spring.NET的IoC容器将会把对MyMovieLister对象的引用注入到MyMovieLister对象的MovieFinder属性中去。这样,在程序中引用的MovieFinder对象即配置完毕,可以列出某导演导过的所有电影。

#001 ...

#002 public static void Main ()

#003 {

#004 IApplicationContext ctx = ContextRegistry.GetContext();

#005 MovieLister lister = (MovieLister) ctx.GetObject ("MyMovieLister");

#006 Movie[] movies = lister.MoviesDirectedBy("Roberto Benigni");

#007 Console.WriteLine ("\nSearching for movie...\n");

#008 foreach (Movie movie in movies)

#009 {Console.WriteLine (

#010 string.Format ("Movie Title = '{0}', Director = '{1}'.",

#011 movie.Title, movie.Director));}

#012 Console.WriteLine ("\nMovieApp Done.\n\n");

#013 }

#014 ...也可以使用构造注入的方法,读者可以自己考虑构造注入方法的实现方式,这里就不再具体介绍。