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

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
I
InfoQ
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Check Point Blog
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
U
Unit 42
N
Netflix TechBlog - Medium
The Cloudflare Blog
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
B
Blog
S
Securelist
H
Hacker News: Front Page
Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog

博客园 - DongD

今天在ASP.NET上在写一个读取EXCEL文件内容的功能,但是IE8貌似把文件路径给屏蔽了,在IE6下面读取正常!有啥好办法? 刚看了一点Spring .NET, 从第一个例子MovieFinder说起(2) RegularExpressionValidator控件中正则表达式用法[转] 一个计算周次和本周时间范围的代码(c#) ASP.NET 安全认证(二)【转】 ASP.NET 的安全认证 - DongD - 博客园 Host and Workflow: Two Worlds to Communicate: Part III Host and Workflow: Two Worlds to Communicate - Part II Host and Workflow: Two Worlds to Communicate: Part I .NET2.0正则表达式【转】 解决Active Directory密码不满足密码策略的要求 Gridview控件中字符串的截取【转】 asp.net(c#)常用正则表达式实例 C#中的delegate和event 【转】 Asp.net &C#开发中的一些注意事项及小技巧【转】 C# 事件机制【转】 asp.net中为TextBox Web服务器控件添加OnClick事件【转】 gridview在绑定显示的各种格式 跳楼有感【转载】
刚看了一点Spring .NET, 从第一个例子MovieFinder说起
DongD · 2012-06-09 · via 博客园 - DongD

看类图关系,一个MovieList类引用一个IMoveFinder对象,ImoveFinder有一个FindAll()的方法,此例中由SimpleMovieFinder 实现。实际上就是由SimpleMovieFinder 实现ImoveFinder接口,而MovieLister只知道ImoveFinder接口,是运行时动态确定ImoveFinder究竟是怎么实现的。

 几本思想就是:多态 +  面向接口编程

在Spring .Net中是用  Injection 的方式实现的。把 MovieList看作一个容器,在Config中声明。

 <objects xmlns="http://www.springframework.net">

    

<object name="MyMovieLister"
      type
="Spring.Examples.MovieFinder.MovieLister, Spring.Examples.MovieFinder">
    </object>
  </objects>

 把SimpleMovieFinder作为Inject(注入)MovieList的对象。也在Config中声明

<object name="MyMovieFinder"
        type
="Spring.Examples.MovieFinder.SimpleMovieFinder, Spring.Examples.MovieFinder"/>

 </object>

把两个对象关联起来,在Config中完整的配置如下

<objects xmlns="http://www.springframework.net">
    <object name="MyMovieLister"
      type
="Spring.Examples.MovieFinder.MovieLister, Spring.Examples.MovieFinder">
        <!-- using setter injection... -->
        <property name="movieFinder" ref="MyMovieFinder"/>
    </object>
    <object name="MyMovieFinder"
        type
="Spring.Examples.MovieFinder.SimpleMovieFinder, Spring.Examples.MovieFinder"/>
    </object>

</objects>  

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

是根据 MovieLister的属性来配置的

private IMovieFinder _movieFinder; 

public IMovieFinder MovieFinder

        {
            get
            {
                return _movieFinder;
            }
            set
            {
                _movieFinder = value;
            }
        }

 

MovieLister 中IMovieFinder 的一个引用,需要做的就是把一个IMovieFinder 的实现注入给它,就是用注入的对象实例化这个接口。

有人可能问了:这个用代码的方式也很容易实现,为啥要用配置的方式呢?我也刚看了一小会,知道究竟怎么个回事了再说!

或者哪位大师知道用配置方式实现的好处,可以先透露一下!!