《.NET分布式应用程序开》读书笔记 第二章:.NET组件
2009-08-15 15:57
225 查看
一:什么是组件,它和程序集有何区别?
组件,可能是一个类或控件,或一组类,现实一个特定的功能,提供一些特定的信息。
程序集是物理的文件,是部署时的单元。可以说程序集包括组件。
二:分布式应用中组件分为两种
服务提供程度(Service-Provider),它通常是无状类的,只封闭特定的功能。如Data access object,Business object,Web service object。。。这些对象通常会被远程激活,所以它们一般继承于:
System.MarshalByRefObject,这样的对象才能被.NET Remoting激活
System.Web.Services.WebService,作为ASP.NET中的一个服务程序
System.EnterpriseServices.ServicedComponent,COM+对象,拥有COM+所提供的一切功能。如:分布式事务,对象池,JIT。
信息的载体(Information Container),就是我们通常说的实体类,VO。贫血模型。因为它会被在不同的进程中传递,所以在标记为可序列化。在C#中,最简单的方法是加上[Serializable]属性。
三:组件示例
最常见的组件可能就是数据访问对象了。下例中,我们要为Customer建立数据访问的组件。
namespace Net.Distributed.App
{
///Customer table data access components (Service Provider)
public class CustomerDb : System.ComponentModel.Component
{
public void AddCustomer(CustomerDetail customer)
{
throw new System.NotImplementedException();
}
public void UpdateCustomer(CustomerDetail customer)
{
throw new System.NotImplementedException();
}
public CustomerDetail GetCustomerById(int customerId)
{
throw new System.NotImplementedException();
}
}
}
namespace Net.Distributed.App
{
///Customer Information Container classs
public class CustomerDetail:System.ComponentModel.Component
{
public int CustomerId
{
get;
set;
}
public string CustomerName
{
get;
set;
}
public string Email
{
get;
set;
}
public string Password
{
get;
set;
}
}
}
注意:你不必继承自Component类,这里这样做,主要是让它们可以在VS中显示在IDE中。方便设计时使用。
组件,可能是一个类或控件,或一组类,现实一个特定的功能,提供一些特定的信息。
程序集是物理的文件,是部署时的单元。可以说程序集包括组件。
二:分布式应用中组件分为两种
服务提供程度(Service-Provider),它通常是无状类的,只封闭特定的功能。如Data access object,Business object,Web service object。。。这些对象通常会被远程激活,所以它们一般继承于:
System.MarshalByRefObject,这样的对象才能被.NET Remoting激活
System.Web.Services.WebService,作为ASP.NET中的一个服务程序
System.EnterpriseServices.ServicedComponent,COM+对象,拥有COM+所提供的一切功能。如:分布式事务,对象池,JIT。
信息的载体(Information Container),就是我们通常说的实体类,VO。贫血模型。因为它会被在不同的进程中传递,所以在标记为可序列化。在C#中,最简单的方法是加上[Serializable]属性。
三:组件示例
最常见的组件可能就是数据访问对象了。下例中,我们要为Customer建立数据访问的组件。
namespace Net.Distributed.App
{
///Customer table data access components (Service Provider)
public class CustomerDb : System.ComponentModel.Component
{
public void AddCustomer(CustomerDetail customer)
{
throw new System.NotImplementedException();
}
public void UpdateCustomer(CustomerDetail customer)
{
throw new System.NotImplementedException();
}
public CustomerDetail GetCustomerById(int customerId)
{
throw new System.NotImplementedException();
}
}
}
namespace Net.Distributed.App
{
///Customer Information Container classs
public class CustomerDetail:System.ComponentModel.Component
{
public int CustomerId
{
get;
set;
}
public string CustomerName
{
get;
set;
}
public string Email
{
get;
set;
}
public string Password
{
get;
set;
}
}
}
注意:你不必继承自Component类,这里这样做,主要是让它们可以在VS中显示在IDE中。方便设计时使用。
相关文章推荐
- [读书笔记]组件设计:补白[深入剖析ASP.NET组件设计]一书中HttpApplication对象创建的细节
- Visual Basic .NET Power Coding 读书笔记之第二章 继承和接口
- [读书笔记][深入剖析ASP.NET组件设计]一书第三章关于ASP.NET运行原理讲述的补白
- ASP.NET自定义控件组件开发 第二章 继承WebControl的自定义控件
- Asp.net组件与控件开发读书笔记
- [读书笔记][深入剖析ASP.NET组件设计]一书第三章关于ASP.NET运行原理讲述的补白
- ASP.NET自定义控件组件开发 第二章 继承WebControl的自定义控件
- 关于ASP.NET中调用Excel组件不能结束进程的解决方法
- 读书笔记: CLR篇 (让你了解C#.Net的实质) (20111219更新)
- ASP.NET组件DataGrid的分页实用方法
- 图片批量缩略图组件(dll),支持asp,asp.net,vb,vb.net等调用
- Python核心编程(第3版)-第二章-网络编程-读书笔记
- Visual Studio .NET 无法创建或打开应用程序。问题很可能是因为本地Web服务器上没有安装所需的组件。请运行 Visual Studio .NET 安装程序并添加Web开发组件。
- [Professional ASP.NET Design Pattern 读书笔记系列] 06 服务层
- KTDictSeg 一个C#.net做的简单快速准确的开源中文分词组件
- 深入浅出React之第二章:如何设计高质量的react组件
- ASP.NET分页组件学与用——教学篇(源代码)
- asp.net 组件开发中的内嵌资源引用
- ASP.NET 揭秘 第二章用Web Server Controls建立Forms
- vb.net 教程 11-1 打印组件 2 PrintDialog 2