PETSHOP代码Word文档格式.docx
- 文档编号:356745
- 上传时间:2023-04-28
- 格式:DOCX
- 页数:37
- 大小:367.17KB
PETSHOP代码Word文档格式.docx
《PETSHOP代码Word文档格式.docx》由会员分享,可在线阅读,更多相关《PETSHOP代码Word文档格式.docx(37页珍藏版)》请在冰点文库上搜索。
Building
Distributed
Applications
Microsoft.NETPetShop4:
MigratinganASP.NET1.1Applicationto2.0
GregoryLeake
MicrosoftCorporation
AlanLe,AlexArkhipov,MikeHanley,andSteveNyholm
VertigoSoftware,Inc.
February2006
Appliesto:
Microsoft.NETFramework2.0
MicrosoftVisualStudio2005
MicrosoftWindowsServer2003
MicrosoftInternetInformationServices
MicrosoftMessageQueuing
MicrosoftSQLServer2005
Oracle10gDatabase
Summary:
The.NETPetShopapplicationisdesignedtoshowthebestpracticesforbuildingenterprise,n-tier.NET2.0applicationsthatmayneedtosupportavarietyofdatabaseplatformsanddeploymentscenarios.(25printedpages)
Clickheretodownload.NETPetShop4.0.msi.
Contents
ExecutiveOverview
Productivity
MigrationfromASP.NET1.1to2.0
Architecture
AbstractFactoryPattern
UserInterfaceEnhancements
EncryptingConfigurationInformation
ModelObjects
OrderandInventorySchema
ProfileDatabaseSchema
Conclusions
The.NETPetShopapplicationisdesignedtoshowthebestpracticesforbuildingenterprise,n-tier.NET2.0applicationsthatmayneedtosupportavarietyofdatabaseplatformsanddeploymentscenarios.
Thegoalsofthe.NETPetShop4projectare:
1.Productivity:
Reducetheamountofcodefrom.NETPetShop3—weachievednearly25percentreduction.
2.MigratefromASP.NET1.1to2.0:
LeveragenewfeaturesofASP.NET2.0—wetookadvantageofMasterPages,Membership,andProfileanddesignedanew,appealinguserinterface.
Figure1.The.NETPetShop4.0
3.Enterprisearchitecture:
Buildaflexible,bestpracticeapplication—weimplementeddesignpatternsandseparationofpresentation,business,anddatatiers.
Whencomparedto.NETPetShop3,thereisroughly25percentlesscodein.NETPetShop4.Themaingainsinreducinglinesofcodeareinthepresentationlayeranddataaccesslayer.
Inthepresentationlayer,wereducedthecodebyroughly25percent.Thesign-inandcheck-outstepsaremorecompactthanfullASP.NETpagesandrequirelesscodeandhtml.ThisisbecausetheWizardcontrolnativelyhandlestheprocessflowcode.UsingtheMasterPagemeantlesshtmlcodeandusercontrolstomanagelayout.MembershipserviceshandlesauthenticationmoresuccinctlythanthePetShop3usermanagementcode.
Wesawthebiggestcodesavingsinthedatatier—36percent.TheaccountmanagementcodeisreplacedbytheASP.NET2.0SQLMembershipProvider.
Table1givesacompletecodecountbreakdownbytier.
Table1.Codecountcomparisonfor.NETPetShopVersion3versusVersion4
v3
v4
PresentationLayer
1,822
1,365
Model
349
395
BusinessLogicLayer
210
199
DataAccessLayer
1,538
985
TotalLinesofCode
3,919
2,944
ThisisfurtherillustratedintheFigure2.
Figure2.CodeCountComparisonGraph
.NETPetShop4introducesseveralnewfeatures,rangingfromacustomASP.NET2.0profileprovidertoasynchronousorderprocessingwithMSMQ.Thecodecountforthenewfeaturesisbrokendownintable2:
Table2.CodeCountofNew.NETPetShop4Features
CustomProfile
853
OracleMembership
586
CacheDependency
90
MessageQueue
147
1,676
Toaccomplishthegoalsfor.NETPetShop4,wedevisedthefollowingplan:
1.UsetheProjectConversionWizardtoportthe.NETPetShop3.2codebasefromASP.NET1.1toASP.NET2.0.
2.MapouttheASP.NET2.0featuresthatwewanttoinclude.
3.Implementann-tierarchitecturethatsupportsthosefeatures.
TheProjectConversionWizard
Tostartoff,theVisualStudio.NET2005ProjectConversionWizardrapidlyupgradedthe.NETPetShop3.2codebase.Withthisbasicportwewereablegetafirstglimpseat.NETPetShop3.2compiledandrunningonASP.NET2.0.
ChangesBetweenVersion3andVersion4
Basedonmovingthe.NETPetShop3.2codebasetorunonthe.NETFramework2.0andourresearchintoASP.NET2.0,wecameupwiththefollowingkeyfeaturestoimplementin.NETPetShop4.0:
∙System.TransactionsinsteadofServicedComponents.
∙GenericsforstronglytypedcollectionsinsteadoflooselytypedILists.
∙ASP.NET2.0Membershipforuserauthenticationandauthorization.
∙CustomASP.NET2.0MembershipProviderforOracle10g.
∙ASP.NET2.0CustomOracleandSQLServerProfileProvidersforuserstatemanagement.
∙MasterPagesforconsistentlookandfeelversusASP.NETWebUserControls.
∙ASP.NET2.0Wizardcontrol.
∙DatabaselevelcacheinvalidationusingSqlCacheDependencyinsteadoftimeoutbased.
∙EnablingAsynchronousOrderProcessingbuiltonmessagequeuing.
WhatisSystem.Transactions?
System.Transactionsisanewtransactioncontrolnamespaceinthe.NET2.0Framework.ItisanewwaytohandledistributedtransactionswithouttheoverheadofCOM+registrationandtheCOM+catalog.NotethattheMicrosoftDistributedTransactionCoordinatorisusedtoinitiatethetransactions.
Seeitinaction
TheOrder.Insert()methodinsynchronousorderprocessingusesSystem.Transactionstoinsertanorderandupdatetheinventorystock.WehaveimplementedtheOrder.Insert()methodbyaddingareferencetotheSystem.TransactionnamespaceandwrappingtheorderinsertionandinventorystockreductionmethodsinsideofaTransactionScope,asshowninCodeListing1.
Listing1.System.Transactionsinaction
Copy
usingSystem;
usingSystem.Transactions;
usingPetShop.IBLLStrategy;
namespacePetShop.BLL{
///<
summary>
///ThisisasynchronousimplementationofIOrderStrategy
///ByimplementingIOrderStrategyinterface,thedevelopercan
///addaneworderinsertstrategywithoutre-compilingthewhole
///BLL.
/summary>
publicclassOrderSynchronous:
IOrderStrategy{
...
///Insertstheorderandupdatestheinventorystockwithin
///atransaction.
paramname="
order"
>
Allinformationabouttheorder<
/param>
publicvoidInsert(PetShop.Model.OrderInfoorder){
using(TransactionScopets=new
TransactionScope(TransactionScopeOption.Required)){
dal.Insert(order);
//Updatetheinventorytoreflectthecurrentinventory
//aftertheordersubmission.
Inventoryinventory=newInventory();
inventory.TakeStock(order.LineItems);
//CallingCompletecommitsthetransaction.
//ExcludingthiscallbytheendofTransactionScope'
s
//scopewillrollbackthetransaction.
ts.Complete();
}
}
In.NETPetShop3,distributedtransactionsarehandledbyEnterpriseServicesandrequireCOM+registration.TheOrderInsertclassisderivedfromaServicedComponentandtransactionsarehandledbyCOM+.Theservicecomponentisthenregisteredusingtheregsvr32command.
Listing2.PetShop3OrderInsert
usingSystem.Collections;
usingSystem.EnterpriseServices;
usingSystem.Runtime.InteropServices;
...
///Abusinesscomponenttomanagethecreationoforders
///Creationofanorderrequiresadistributedtransaction
///sotheOrderclassderivesfromServicedComponents
[Transaction(System.EnterpriseServices.TransactionOption.Required)]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ObjectPooling(MinPoolSize=4,MaxPoolSize=4)]
[Guid("
14E3573D-78C8-4220-9649-BA490DB7B78D"
)]
publicclassOrderInsert:
ServicedComponent{
///Amethodtoinsertaneworderintothesystem
///TheorderIdwillbegeneratedwithinthemethodandshouldnot
///besuppliedaspartoftheordercreationtheinventorywillbe
///reducedbythequantityordered.
Alltheinformationabouttheorder<
returns>
///TheneworderIdisreturnedintheorderobject
/returns>
[AutoComplete]
publicintInsert(OrderInfoorder){
//GetaninstanceoftheOrderDALusingtheDALFactory
IOrderdal=PetShop.DALFactory.Order.Create();
//CalltheinsertmethodintheDALtoinserttheheader
intorderId=dal.Insert(order);
//GetaninstanceoftheInventorybusinesscomponent
inventory.TakeStock(order.LineItems);
//SettheorderIdsothatitcanbereturnedtothecaller
returnorderId;
BenefitofSystem.Transactions
MovingfromEnterpriseServicestoSystem.TransactionssimplifiesdeploymentasitdoesnotrequiretheuseoftheCOM+Catalog.InusingtheCOM+Catalogwewerecarryingaroundalotofextraweightforjustdistributedtransactionsupport.System.TransactionmakesitreallysimpletoprogramanddeploydistributedapplicationsinASP.NET2.0applications.System.Transactionsisalsoupto50percentmoreperformantatruntime,duetoremovingtheoverheadofCOM+cataloglookupsforobjectinstantiation.Asafinalbenefit,System.Transactionsisabletodetect,whenrunningagainstSQLServer2005,whenadistributedtransactionisrunningagainsttwodifferentdatabasesthatarehostedonasingleinstanceofSQLServer2005.Inthiscase,itisabletopromotethedistributedtransactiontoalocaltransaction,whichavoidsalloverheadassociatedwithdistributedtransactionlogging/twophasecommits,andsignificantlyincreasesperformance.
Generics
WhatareGenerics?
Wheneveraco
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- PETSHOP 代码
![提示](https://static.bingdoc.com/images/bang_tan.gif)