地址:http://www.aspspider.com/

现在还有开放名额,过期可能没了!

posted @ 2008-10-25 15:21 Ralax 阅读(718) | 评论 (0)编辑

www.cnblogs.com的配置:

  1. Blog服务选择“自定义博客”
  2. Blog类型选择“MetaWeblog API”
  3. 服务器API URL:http://www.cnblogs.com/{UserName}/services/metaweblog.aspx
  4. 如果需要Home Page,就把你的访问地址:http://www.cnblogs.com/{UserName}
  5. 最后用户名和密码就OK了。
weblogs.asp.net配置:
  1. Blog服务选择“自定义博客”
  2. Blog类型选择“MetaWeblog API”
  3. 服务器API URL:http://weblogs.asp.net/metablog.ashx
  4. 如果需要Home Page,就把你的访问地址:http://weblogs.asp.net/{UserName}
  5. 最后用户名和密码就OK了。
posted @ 2008-04-01 22:16 Ralax 阅读(85) | 评论 (0)编辑

WCF --- Windows Communiction Foundation,是一个Microsoft推出已久的技术。已久有很多人写了不少关于WCF的文章,比如谈谈WCF系列等,都是很好的文章。我只是想说一些基础的东西,然后写一个例子,让目前刚开始学习WCF的人有一个感性的了解,希望能给他们的学习带来一点用处,同时是自己对WCF认识加深的一个过程。

WCF是一个统一的,可用于建立安全,可靠的面向服务的应用高效的开发平台。WCF是构建安全可靠的事务性服务的统一框架。它是一种构建分布式面向服务系统的非常丰富的技术基础,它统一了消息风格和RPC[Remote Procedure Call]风格,并且通过二进制和基于开放标准的通信达到了平台最优化。

它整合了.Net平台下所有的和分布式系统有关的技术,例如ASP.NET Web服务(ASMX)、增强Web服务扩展(WSE)、.Net Remoting、企业服务(Enterprise Service)和微软消息队列(MSMQ)。

而要理解WCF,你首先要理解WCF基本的组成部分,分别为:

  • Message  --- Soap Message, WCF不仅支持XML格式,而且还支持更加高效的Binary格式
    • Header   --- Message的Header,通常是附属信息,可以零个或多个
    • Body  --- Message的Body,通常是主题信息,可以零个或多个
  • Channel  --- 传输Message的通常,可以建立多个Channel,通常包括下面四部分信息,但一般不用我们指定,而是在配置Service/Endpoint中指定
    • Security  --- 传输安全性
      • Message Securty  --- Message的安全性,通常验证方式有Windows Authentication 或 X.509 或 Custom
        • Authentication  --- 验证
        • Integrity  --- 消息完整性
        • Confidentiality  --- 消息机密性,加密解密
        • Auditing  --- 审核
      • Transport Security  --- Transport的安全性
        • Https  --- 针对Http来说的安全传输
        • Other
    • Interoperability  --- 交互性,我的理解是,可以替代的服务类型
      • WebService
      • WSE
      • .Net Remoting
      • Enterprise Service
      • MSMQ
      • Other
    • Message pattern  --- Message的传输方式
      • Simplex  --- 单向传输,如A-->B
      • Duplex  --- 双向传输,如A<---->B,A先发送信息到B,B返回一个状态,然后A再发Message,然后B Response
      • Request-Respose  --- 要求/回复,A-->B,B-->A
    • Transport  --- 传输类型,Message是通过什么形式传输的
      • Http --- 无需保存连接状态
      • Tcp --- 需要保存连接状态,在Exchange Data的时候,会维护一个State
      • MSMQ  --- 通常用于需要可靠的Message传输的时候
      • Named Pipes  --- 通常用于单个PC的不同进程间通信
  • Service
    • Service
      • Contract  --- 契约
        • Data Contract  --- 数据契约,告诉程序该数据可以用于WCF传输,通常用来指定我们自定义的Model对象,是serializable的一种类型,命名空间为System.Runtime.Serialize。
        • Service Contract  --- 服务契约,告诉程序这是该一个WCF服务
        • Operation Contract  --- 操作契约,告诉程序,这是该Service对外暴露的可以执行的操作
      • Implementation  --- Operation Contract的具体实现
    • Endpoint --- 在外界看来,服务的连接接地址
      • Address  --- 服务的具体地址,根据Transport类型,可以是Http,Tcp等
      • Binding  --- 下面的图标是Binding的不同类型
      •   image
      • Contract  --- 对外暴露的接口
    • Behavior  --- Service在执行时,要执行的一个行为,比如安全验证
      • Throttling  --- 决定同一时间一个Service可以使用的Thread数量、Service的实例数,传递的Message数量
      • Security  --- 决定Service的安全特性
      • Instancing  --- 决定Service实现类的可以创建的实例数
        • PerCall  --- 客户端的每次Request都会产生一个InstanceContext
        • PerSession  --- 根据每个客户端的Session来产生一个InstanceContext,并且和这个Session有相同的生命周期
        • Single  --- 单例模式
      • Error Handling  --- 但Service遇到异常并且需要返回信息时的处理方式
      • Concurrency  --- 控制一个InstanceContext可以跨多少个线程
        • Multiple  --- 可以跨多个线程
        • Single  --- 只能在单行程内执行
        • Reentrant  --- Each instance of the service can only process messages one at a time but can accept re-entrant operation calls
      • Transactions  ---  决定Service是否可以接受并执行来自客户端的事务.注意事务是客户端创建的,因此事务的完成与否由客户端决定,当然生命周期也是如此。
      • Custom  --- 自定义行为
    • Host  --- WCF的寄宿主,即运行Service的地方
      • Console Application
      • Web Application
      • WinForms Application
      • IIS
      • Service

image

下面我做一个简单实例来说明一下,一个WCF的开发,调用过程。

一,首先我们创建一个Console Application,叫做WCFDemo

image

二,我们既然要开发WCF,当然要引入一个WCF Service Application了,叫做Service,如果你不想创建单独的项目,你可以在别的项目中添加WCF Service的Item。在创建WCF Project的时候会自动生成IService和Service.svc,通常IService这个Service Contract我们是不会要的,因为调用Service的Client也需要用,所以我们会把他们放到统一的地方,本例中是叫Interface的项目。单纯的Service.svc是很简单的一个实现了IService接口的一个类,没有什么特别之处,

   1:  namespace Service
   2:  {
   3:      // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file.
   4:      public class Service : IService
   5:      {
   6:          public Computer GetComputer()
   7:          {
   8:              Computer computer = new Computer();
   9:              computer.ComputerName = "Ralax - PC";
  10:              return computer;
  11:          }
  12:      }
  13:  }

而一个值得我们注意的地方就是,如果我们的Service名称变换了,一定要记得在Service.svc的Markup的CodeBehind修改引用,

   1:  <%@ ServiceHost Language="C#" Debug="true" Service="Service.Service" CodeBehind="Service.svc.cs" %>

而作为Service的Config,应该是很重要的一个地方了,Config是配置Service如何运行,如何访问等的很重要的地方。如下:

   1:    <system.serviceModel>
   2:      <services>
   3:        <service name="Service.Service" behaviorConfiguration="Service.ServiceBehavior">
   4:          <!-- Service Endpoints -->
   5:          <endpoint address="" binding="wsHttpBinding" contract="Interface.IService">
   6:            <!-- 
   7:                Upon deployment, the following identity element should be removed or replaced to reflect the 
   8:                identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
   9:                automatically.
  10:            -->
  11:            <identity>
  12:              <dns value="localhost"/>
  13:            </identity>
  14:          </endpoint>
  15:          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  16:        </service>
  17:      </services>
  18:      <behaviors>
  19:        <serviceBehaviors>
  20:          <behavior name="Service.ServiceBehavior">
  21:            <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
  22:            <serviceMetadata httpGetEnabled="true"/>
  23:            <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
  24:            <serviceDebug includeExceptionDetailInFaults="true"/>
  25:          </behavior>
  26:        </serviceBehaviors>
  27:      </behaviors>
  28:    </system.serviceModel>

这里面很重要的部分,就是endpoint的配置ABC,address,binding和contract,另外还有bindingConfiguration,behavirorConfiguration等。

三,我刚才提到IService被提到Interface这个项目中,共Client和Service共同使用,其实IService更加简单,就是一个加了ServiceContract的interface,和一些加了OperationContract的Methods。

   1:  namespace Interface
   2:  { 
   3:      [ServiceContract]
   4:      public interface IService
   5:      {
   6:          [OperationContract]
   7:          Computer GetComputer();
   8:      }
   9:  }

四,另外一个项目就是Data,这个项目是我们的Model类,加上了DataContract就可以就可以用于WCF传输,同时对于公开的Property,需要加上DataMember。

   1:  namespace Data
   2:  {
   3:      [DataContract]
   4:      public class Computer
   5:      {
   6:          private string computerName;
   7:          [DataMember]
   8:          public string ComputerName
   9:          {
  10:              get { return computerName; }
  11:              set { computerName = value; }
  12:          }
  13:      }
  14:  }

完成了上面的部分,也可以说一个Service也就完成了,剩下的就是客户端的调用了。

五,在Console Application中创建一个Service的客户端代理类,如下:

   1:  namespace WCFDemo
   2:  {
   3:      public class ServiceClient : ClientBase<IService>,IService
   4:      {
   5:          public ServiceClient(System.ServiceModel.Channels.Binding binding,EndpointAddress remoteAddress) : base(binding,remoteAddress)
   6:          {
   7:              
   8:          }
   9:   
  10:          public Computer GetComputer()
  11:          {
  12:              return base.Channel.GetComputer();
  13:          }
  14:      }
  15:  }

需要注意的是,ServiceClient继承关系,以及构造函数

ServiceClient完成后,就是Client的调用了,如下:

   1:  namespace WCFDemo
   2:  {
   3:      class Program
   4:      {
   5:          static void Main(string[] args)
   6:          {
   7:              using(ServiceClient sClient = GetService())
   8:              {
   9:                  Console.WriteLine(sClient.GetComputer().ComputerName);
  10:                  Console.Read();
  11:              }            
  12:          }
  13:   
  14:          public ServiceClient GetService()
  15:          {
  16:              WSHttpBinding binding = new WSHttpBinding();
  17:              EndpointAddress address = new EndpointAddress(new Uri("http://localhost/WCFDemo/Service.svc"));
  18:              ServiceClient client = new ServiceClient(binding, address);
  19:              return client;
  20:          }
  21:      }
  22:  }
 
这个例子,我已经打包了,可以在这里下载:http://www.cnblogs.com/Files/myg2006/WCFDemo.rar
posted @ 2008-03-09 11:35 Ralax 阅读(16584) | 评论 (19)编辑
如果我们在一个MainForm下面调用另外一个PopForm时,这个时候如果PopForm需要自己动态加载控件或者数据量比较大的话,在PopForm.ShowDialog()的时候,屏幕会有闪动现象,而一直也没有找到一个比较好的解决方案。
而目前只有一个暂时的解决方案,如下:
MainForm.TopMost = true;
PopForm.Owner = MainForm;
PopForm.TopMost = true;
PopForm.ShowDialog();
用这个代码就可以解决闪动的问题,但是要注意的是,在PopForm的Load或其他ShowDialog后立即要执行的事件或方法中加上如下代码:
this.TopMost = false;
this.Owner.TopMost =false;
这样就可以避免你无法切换到别的Application。

这个方法并不是我想要的方法,不是从根本上解决问题的方法,不知道哪位有更好的方法,望指教!


posted @ 2008-02-21 14:01 Ralax 阅读(146) | 评论 (1)编辑

工厂方法模式与抽象工厂模式,两个模式比较相似,把任何一个独立出来,好像都不太好,所以把它们放到一起来理解会更好。不管是工厂方法还是抽象工厂,都有三个要素,那就是Client,Factory,Product。

首先看一下工厂方法模式

定义一个创建对象的接口,然后把对象的创建放到子类中进行。也就是说,我们要定义一个IFactory(可以是类,抽象类,也可以是接口),然后有一些具体的Factory继承自它,如AFactory,BFactory等。然后Product的创建就放到AFactory或BFactory来实现。注意这里,一个Factory只生产一种Product,这一点很重要。一个现实的例子就是,假如我们(Client)要配一台电脑(主机PC+显示器Screen),我们就要去不同的厂家(IFactory)去购买。过程为:

Client à Factory à Product à Client。我们用代码表示如下:

    9     public class Product

   10     {

   11         //...

   12     }

   13     public class PC : Product

   14     {

   15         //...

   16     }

   17     public class  Screen : Product

   18     {

   19         //...

   20     }

   21     public interface  IFactory

   22     {

   23         Product CreateProduct();

   24     }

   25     public class  PCFactory : IFactory

   26     {

   27         public Product CreateProduct()

   28         {

   29             return new PC();

   30         }

   31     }

   32     public class ScreenFactory : IFactory

   33     {

   34         public Product CreateProduct()

   35         {

   36             return new Screen();

   37         }

   38     }

 

   40     public class Client

   41     {

   42         public void BuySome()

   43         {

   44             List<IFactory> factories = new List<IFactory>();

   45             factories.Add(new PCFactory());

   46             factories.Add(new ScreenFactory());

   47 

   48             foreach (IFactory factory in factories)

   49             {

   50                 factory.CreateProduct();

   51                 //...

   52             }

   53         }

   54     }

 

抽象工厂模式:

上面我们曾提到,工厂方法模式是一个Factory只产生一种Product,而对抽象工厂模式来说,就是一个工厂生产多种Product。也就是说这个时候Product已经不是一种了,而是多种。一句话,就是由一个工厂(Factory)生产不同的产品(Product)来满足Client的需求。

代码如下:

    9     public class PCProduct

   10     {

   11         //...

   12     }

   13     public class ScreenProduct

   14     {

   15 

   16     }

   17     public class APC : PCProduct

   18     {

   19         //...

   20     }

   21     public class BPC : PCProduct

   22     {

   23         //...

   24     }

   25     public class  AScreen : ScreenProduct

   26     {

   27         //...

   28     }

   29     public class  BScreen : ScreenProduct

   30     {

   31         //...

   32     }

   33     public interface  IFactory

   34     {

   35         PCProduct CreatePCProduct();

   36         ScreenProduct CreateScreenProduct();

   37 

   38     }

   39     public class  AFactory : IFactory

   40     {

   41         public PCProduct CreatePCProduct()

   42         {

   43             return new APC();

   44         }

   45 

   46         public ScreenProduct CreateScreenProduct()

   47         {

   48             return new AScreen();

   49         }

   50     }

   51     public class BFactory : IFactory

   52     {

   53         public PCProduct CreatePCProduct()

   54         {

   55             return new BPC();

   56         }

   57 

   58         public ScreenProduct CreateScreenProduct()

   59         {

   60             return new BScreen();

   61         }

   62     }

   63 

   64     public class Client

   65     {

   66         public void BuySome()

   67         {

   68             List<IFactory> factories = new List<IFactory>();

   69             factories.Add(new AFactory());

   70             factories.Add(new BFactory());

   71 

   72             foreach (IFactory factory in factories)

   73             {

   74                 factory.CreatePCProduct();

   75                 factory.CreateScreenProduct();

   76                 //...

   77             }

   78         }

   79     }

 

从上面代码,我们可以看出,从工厂方法到抽象工厂,他的变化,就在于Product由一种变成了多种,而Factory由生产一种产品变成了多种,虽然看似很小的变化,但产生的意义是很大的。

对比工厂方法,抽象工厂的意义" 提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类",我们发现,抽象工厂的对象加了形容词"一系列相关或相互依赖"。

 

根据他们的意义,我们可以推测他们的适用性,也就是哪里可以使用,在这里就不再叙述。

 

 

posted @ 2008-02-20 16:28 Ralax 阅读(722) | 评论 (0)编辑

关于Ioc和DI前两天写了一个关于自己的理解的文章,有的朋友说需要一个例子能更好的解释,今天就来发一个

例子是一个Console程序,我自定义了四个类和一个接口,分别为Employee,GetRealNameCommand,GetNickNameCommand,Company,接口为ICommand。

Employee只有两个属性RealName和NickName,ICommand也只有一个方法Execute来处理Employee,具体怎么操作,由子类定义。

具体的两个Command类分别获取Employee的NickName和RealName。

Company类内部包含一个Employee的List和一个DoExecute方法,具体执行什么,由我们的程序指定。

我们首先看一下Main方法中是怎么执行的,

static void Main(string[] args)

{

Console.WriteLine("The setter inject......");

using (Company company = new Company())

{

company.Persons.AddRange(new Employee[]

{

new Employee("MyNickName","MyRealName"),

new Employee("YourNickName","YourRealName"),

}

);

GetNickNameCommand getNickNameCommand = new GetNickNameCommand();

Console.WriteLine("The first inject......\r\n Get the person's NickName");

这里就可以理解为注入

company.Command = getNickNameCommand;

这里就是一个我理解的Ioc的控制反转

company.DoExecute();

Console.ReadLine();

 

Console.WriteLine("The second inject......\r\n Get the person's RealName");

GetRealNameCommand getRealNameCommand = new GetRealNameCommand();

这里就可以理解为注入

company.Command = getRealNameCommand;

这里就是一个我理解的Ioc的控制反转

company.DoExecute();

 

Console.ReadLine();

 

}

 

Console.WriteLine("The constructor inject......");

这里就可以理解为注入(构造器注入),这种注入无法多次调整

using (Company company = new Company(new GetNickNameCommand()))

{

company.Persons.AddRange(new Employee[]

{

new Employee("MyNickName","MyRealName"),

new Employee("YourNickName","YourRealName"),

}

);

 

Console.WriteLine("The first inject...... \r\n Get the person's NickName");

company.DoExecute();

 

Console.ReadLine();

 

}

}

关于接口注入的方式,我还是认为应该结合构造器和Setter两种方式来配合使用,如果有朋友有更好的理解,希望能给一个关于接口注入的例子。

代码下载地址:http://www.cnblogs.com/Files/myg2006/IocAndDIDemo.rar

posted @ 2008-02-04 15:57 Ralax 阅读(1531) | 评论 (6)编辑

从今天开始,我每周会写一个关于设计模式的文章,还是用自己的语言,从自己的角度来阐述设计模式的用途,好处,以及怎么用。

首先,最简单的也就是单例了,我就用他作为自己的第一篇设计模式的文章吧。

1. 单例的目的是什么?  
   
这个应该很明显,保证一个类只有单一的实例,也就是说你无法通过New或CreateInstance来创建这个类的一个新实例。
2. 单例的好处在哪里?
   
当一个对象在程序内部只能有一个实例的时候,它可以保证我们不会重复创建,而是始终指向同一个对象。
3. 怎么用?
     单例模式的实现代码如下:

namespace SinglePattern
{
     public class SingleClass
     {
         private static SingleClass instance;

         protected SingleClass(){}

         public static SingleClass GetInstance()
         {
             if(instance == null)
             {
                 instance = new SingleClass();
             }
             return instance;
         }

}
}

上面的代码,可以说是一个标准的单例的代码,但是上述代码在多线程的时候有可能会产生多个实例,为了避免这个情况的发生,我们需要限制同一时间,只能有一个线程访问。

利用lock可以实现我们的目的:

namespace SinglePattern
{
     public class SingleClass
     {
         // 静态变量
         private static SingleClass instance;

         // "锁"变量
         private static object lockObject = new objest();

         // 受保护的构造函数
         protected SingleClass(){}

         // 静态获取对象的方法
         public static SingleClass GetInstance()
         {
             lock (lockObject)
             {
                 if (instance == null)
                 {
                     instance = new SingleClass();
                 }
             }
             return instance;
         }

     }
}

另一个方法:

这个方法经过调整之后,也可以用于限制一个窗体只能启动一个实例。

using System.Threading;
namespace SinglePattern
{
     public class SingleClass
     {
         // 静态变量
         private static SingleClass instance;

         // 受保护的构造函数
         protected SingleClass(){}

// 静态获取对象的方法
         public static SingleClass GetInstance()
         {
Mutex mutex = new Mutex();
             mutex.WaitOne();

             if (instance == null)
             {
                 instance = new SingleClass();
             }

             mutex.Close();

             return instance;
         }

     }
}

posted @ 2008-02-03 13:23 Ralax 阅读(5147) | 评论 (20)编辑

A recent office-cleaning turned up a quote I'd kept from an automotive magazine from 20 years ago:

"Protecting drivers from the consequences of bad driving encourages bad driving"

Well, that seems reasonable to me. If you didn't have bumpers, seatbelts, airbags, and whatever...you'd probably be encouraged to drive more carefully, right? And the Darwinian aspect would help cleanse the pool of bad drivers. So, how well would this translate to software development?

"Protecting developers from the consequences of bad coding encourages bad coding"

Of course, it's not just coding - you could substitute architecture or pretty much any other activity and the statement might still be true - and relevant.

Source: http://weblogs.asp.net/kpleas/archive/2008/02/01/encouraging-bad-coding.aspx

如上所述,我们应该逐步的改正写代码中的问题,不然的话,会变得越来越糟!

posted @ 2008-02-02 10:46 Ralax 阅读(104) | 评论 (0)编辑
首先说一下什么是IOC和DI,IOC是Inversion of Control(控制反转)的简写,DI是Dependency Injection(依赖注入)的简写,martinfowler对IOC的解释为:“Inversion of control is a common characteristic of frameworks, so saying that these lightweight containers are special because they use inversion of control is like saying my car is special because it has wheels.”
我想对这一概念进行一个个人的阐述,以方便我的理解。控制反转,从字面意思来看,就是控制权由被动变主动又变为被动,或被动变主动又变为被动。从这个角度来说,IOC就变得非常容易理解了。
举个例子:你的主管要求你做一件事情,这个时候就存在这么几个过程,
  1. 主管命令你做事情(这个时候主动权在主管,你是被动的)
  2. 你接到命令做事情(这个时候主题是你,你是主动的,控制权在你手里)
  3. 你完成事情(这个时候主题依然是你,控制权在你手里)
  4. 报告主管做完事情(主动权又叫交到主管手里了)
上面的整个过程就完成了一次IOC,从上面可以看出,IOC的基本思想是控制权的转换过程。
举个代码的例子:
假如有Class A,Class B,在A内部会初始化一个B,调用B的一个方法DoMethod

public Class B
{
    public void DoMethod()
    {
        /// do somthing;
    }
}
public Class A
{
    public void Excute()
    {
        B b = new B();
        b.DoMethod();
    }
}
假如在Main函数中如下执行:
A a = new A();
a.Excute();
从这两行代码来看,事实上也存在一个IOC的过程,a--->b--->a,理解的关键点就在在A的内部调用Excute的时候,方法b.DoMethod的执行。

理 解了IOC,我们再看一下DI,从上面A调用B我们可以看出,在初始化一个A的实例时,也必须实例化一个B,也就是说如果没有B或者B出了问题,A就无法 实例化,这就产生了一种依赖,就是A依赖B,这种依赖从设计的角度来说就是耦合,显然它是无法满足高内聚低耦合的要求的。这个时候就需要解耦,当然解耦有 很多种方法,而DI就是其中一种。不管任何一种解耦方法,都不是说使A和B完全没有关系,而是把这种关系的实现变得隐晦,不那么直接,但是又很容易实现, 而且易于扩展,不像上面的代码那样,直接new一个B出来。那为什么我们总是把IOC和DI联系到一起呢?是因为DI的基本思想就是IOC,而体现IOC 思想的方法还有另外一个,那就是Service Locator,这个方法好像涉及到的很少。

DI,依赖注入,从字面意思就可以看出,依赖是通过外接注入的方式来实现的。这就实现了解耦,而DI的方式通常有三种,
  1. 构造器注入
  2. 属性设置器注入
  3. 接口注入(我感觉接口注入是同时存在于上两种注入方式的,而不应该独立出来)

以上的阐述只是为了先让我们能对IOC和DI有一个感性的理解,那么IOC他真正解决的问题是什么呢?我们讲了那么多主动被动的问题,那我们是从什么视角 来看待这个问题的呢?所谓为什么你是主动,而我不是主动呢?这就需要一个参照物,那这个参照物是什么呢?就是容器,在容器中来体现主动和被动。“用 白话来讲,就是由容器控制程序之间的关系,而非传统实现中,由程序代码直接操控。这也就是所谓“控制反转”的概念所在:控制权由应用代码中转到了外部容 器,控制权的转移,是所谓反转",这是通常对IOC的一个解释。从容器的角度来看主动和被动,和由容器来控制程序之间的关系,应该是相通的,是一个意思。 到这里我们就应该基本明白了,IOC要解决的就是程序之间调用的一个问题,它应该是一个思想层面的东西,是一个中心,就像一支乐队的指挥,而程序就是乐 器,通过指挥来协调各种乐器,来演奏出美好的音乐来。

以上是我对IOC和DI的理解,希望各位批评指正!





posted @ 2008-01-28 20:52 Ralax 阅读(1989) | 评论 (12)编辑
By Andy Patrizio
January 9, 2008

Developers may now be able to build .NET Framework applications using concepts previously available only on Java, thanks to the release of SpringSource's Spring.Net.

Spring is about "making it easy to swap implementations in and out," Spring.Net Project Lead Mark Pollack told InternetNews.com. "We're not tied to languages but to programming ideas. Spring is bringing ideas developed in Java to .NET."

SpringSource, formerly known as Interface21, previously released the Spring Framework programming model for Java.

The two major Java features of the Spring Framework now available for .NET are dependency injection and an aspect-oriented programming framework, complementing the object-oriented programming (OOP) used in .NET.

Dependency injection is an application configuration concept that makes it easier to swap services. In traditional OOP, when Object A asks for Object B, that hard-codes the objects' connection and dependency. If Object B is replaced or removed, all of the code needs to be changed.

Dependency injection, on the other hand, doesn't rely on Object A asking for Object B.

"Normally, things are hard-coded, making it difficult to test, whereas this approach -- of handing an object what it needs, instead of an object asking for it -- promotes plugability," said Pollack.

The aspect-oriented programming framework allows for performing functions when a method gets called. When the method is called, a predefined behavior or action is initiated.

That way, when the program is doing one task, a second step or process is also invoked to back up, support or operate in tandem with the first process.

This allows for features like caching or exception handling, and is more efficient than starting and stopping a process or having to keep repeating code to perform checks for conditions, Pollack said.

Java has this feature in Enterprise JavaBeans, but SpringSource's Spring.Net now makes it available for the .NET programmer.

Other key features of Spring.Net 1.1 include ASP.NET AJAX (Asynchronous JavaScript and XML) integration and portable service abstraction, to export plain .NET objects via .NET Remoting and other technologies.

It also includes an Aspect Library of predefined, easy-to-use aspects for transaction management, logging, performance monitoring, caching, method retry, and exception handling. Additionally, the release provides Declarative Transaction Management via XML configuration and attributes and ADO.NET Data Access Framework, which simplifies the use of ADO.NET.

Source:http://www.internetnews.com/bus-news/print.php/3720666
posted @ 2008-01-11 09:04 Ralax 阅读(273) | 评论 (1)编辑