<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>A BULL's view of LIFE and TECHNOLOGY : .NET Framework</title><link>http://blogs.msdn.com/ashishme/archive/tags/.NET+Framework/default.aspx</link><description>Tags: .NET Framework</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Approach - how to sync custom entities and dataset</title><link>http://blogs.msdn.com/ashishme/archive/2006/09/15/756266.aspx</link><pubDate>Fri, 15 Sep 2006 20:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:756266</guid><dc:creator>ashishme</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/ashishme/comments/756266.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ashishme/commentrss.aspx?PostID=756266</wfw:commentRss><description>&lt;P&gt;The Problem Statement: &lt;/P&gt;
&lt;P&gt;Web Services A communicates with Web Service B which updates database. The Web Service B use Dataset to handle and update database and depends upon dataset to handle concurrency issues. Where as Web Service A takes dataset from Web Service B converts to Custom entities and pass to Web Application for modification. In reverese the Web Application sends the data as custom entities back to Web Service A which converts the custome data entity back to data set and sends it to Web Service B, but the problem here is that Web Service B handles concurrency issues on basis of datasets, but now as the data set got converted into entities the dataset that is created to send back to web service B only has the new values, so how to solve the concurrency issue.&lt;/P&gt;
&lt;P&gt;The solution definitely involves either sending the dataset through out the layers to web application or somehow persists the old data in case the dataset cannot be passed through the layers as of business constraints&lt;/P&gt;
&lt;P&gt;As the title suggests I would be discussing the later i.e. where dataset cannot be passed to web application but needs to be converted into entities:&lt;/P&gt;
&lt;P&gt;&lt;U&gt;The FIRST approach:&lt;/U&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The&amp;nbsp;Web Application&amp;nbsp;makes a call to Web Service A 
&lt;LI&gt;Web Service A calls the Web Service&amp;nbsp;B to get the dataset 
&lt;LI&gt;Web Service A transform the dataset to custom entity and send it back to Web Application, and discard the dataset 
&lt;LI&gt;Web Application A&amp;nbsp;the persists the entity&amp;nbsp;using viewstate/session 
&lt;LI&gt;Web Application&amp;nbsp;make changes to the entity and now call&amp;nbsp;Web Service A with&amp;nbsp;(oldEntity, newEntity) 
&lt;LI&gt;On&amp;nbsp;Web Service A,&amp;nbsp;create the dataset and set the old values from oldEntity, update the dataset with newValues from newEntity and call Web Service B with dataset having both old and new values. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;U&gt;The&amp;nbsp;Second approach:&lt;/U&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The&amp;nbsp;Web Application&amp;nbsp;makes a call to Web Service A 
&lt;LI&gt;Web Service A calls the Web Service&amp;nbsp;B to get the dataset 
&lt;LI&gt;The dataset is persisted at the&amp;nbsp;web Service A using the Cache distingushed on the basis of UserID and Requesting Page, i.e. use Cache as Session 
&lt;LI&gt;Web Service A transform the dataset to custom entity and send it back to Web Application 
&lt;LI&gt;Web Application&amp;nbsp;make changes to the entity and now call&amp;nbsp;Web Service A with new values 
&lt;LI&gt;Web Service A retrives the dataset based upon the User and the requested page and updates the dataset with new values 
&lt;LI&gt;the cache object is invalidated and Web Service B is called with dataset with old and new values. 
&lt;LI&gt;Cache Expiry and Cache scavenging is also implemented to free up the cache &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;The&amp;nbsp;comparison of 2 approaches:&lt;/P&gt;
&lt;P&gt;From a service orientation perspective that the presentation should only consume and persist the data to the underlying store through the help of these business services and should not be cognizant of the underlying idiosyncrasies regarding the persistence mechanism. If using first approach where presentation tier being cognizant of underlying concurrency issues(by passing 2 entities, old and new). It should only be passing one and only one instance of the entity to the business service to persist the changes that were made in UI.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The approach (i.e. first approach)for cloning and sending old values and the altered values is the approach what&amp;nbsp; Dataset is uses internally. The Dataset implements IBindlingList interface and keeps track of the changes done like deletions, modification etc using the cloning before modifications so that it can maintain existing and the modified data. While analyzing the same approach for the problem&amp;nbsp;I realized that we can tweak it little by passing the old and new entities as separate parameters as we didn’t required the lists of objects being returned at one go where as one entity needs to be modified in one call. Therefore presented the approach in the simple and tweaked format thus gaining on performance and making it simple to implement. &amp;nbsp;The &amp;nbsp;approach can be very well achieved without any tweaking by just passing a single entity to the UI layer which implements the IBindingList interface and follows the cloning approach internally, whereby encapsulating the cloned entity and returning the entity back to the Service Layer as single parameter. &lt;/P&gt;
&lt;P&gt;
&lt;P&gt;If you are planning to cache all the data on the Service Layer, then the approach of caching the dataset&amp;nbsp;might be a good approach, but if it not the case&amp;nbsp;the you must try to analyze that is it worth putting the resources on Service Layer and implementing the cache for just preserving the existing values received from the web services.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even though the first approach outlining has got merit but why would we pay performance penalty for instantiating few more objects? Not to mention, the cost of first constructing a dataset in the update method with first the old entity and then update it with the new entity – Double update for this dataset! Furthermore, from a maintainability standpoint, why not have a simpler model with less code rather than writing more code?&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The debate is still open, please feel free to continue and provide your views.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=756266" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ashishme/archive/tags/.NET+Framework/default.aspx">.NET Framework</category></item><item><title>The CLR (written in native code) is only loaded once per process and the code segments are shared amongst (.NET) processes.</title><link>http://blogs.msdn.com/ashishme/archive/2006/06/09/623831.aspx</link><pubDate>Fri, 09 Jun 2006 17:23:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623831</guid><dc:creator>ashishme</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/ashishme/comments/623831.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ashishme/commentrss.aspx?PostID=623831</wfw:commentRss><description>&lt;div&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;font color="#800080"&gt;"&lt;b&gt;The CLR (written in native code) is only loaded once per process and the code segments are shared amongst (.NET) processes.&lt;/b&gt;"&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;o:p&gt;&lt;font color="#800080"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;font color="#800080"&gt;It sounds as though you are saying for each assembly loaded that does not reference some group of assemblies but works with referenced assemblies in the same process, the CLR is loaded once.&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;o:p&gt;&lt;font color="#800080"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;font color="#800080"&gt;For example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;font color="#800080"&gt;[One CLR instance]&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;font color="#800080"&gt;&amp;nbsp;- A.exe loads - this loads a CLR instance.&amp;nbsp; A.exe references B.dll&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;font color="#800080"&gt;&amp;nbsp;- B.dll loads into the A.exe app domain.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;o:p&gt;&lt;font color="#800080"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;o:p&gt;&lt;font color="#800080"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;font color="#800080"&gt;[Two CLR instances]&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;font color="#800080"&gt;- A.exe loads same as above&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;font color="#800080"&gt;- B.exe loads and only references X.dll.&amp;nbsp; Another CLR instance loads into the B.exe process.&amp;nbsp; X.dll loads into the B app domain.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;o:p&gt;&lt;font color="#800080"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;o:p&gt;&lt;font color="#800080"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;font color="#800080"&gt;Note that it's not quite correct to talk about CLR "instances", the CLR is just a bunch of native code DLL's, and these DLL's are mapped into the process address space. That means that and the "A" process and the "B" process will each map the CLR DLL's. Note that I say 'mapped', that means that while each process will get it's private copy of the non sharable pages in the DLL (some of the data pages) loaded in the process address space, each one will share the sharable pages (the code pages) across the processes. Now, this is exactly what the CLR is unable to do - share JIT compiled code pages across processes and AD's, but NGEN'd code can be shared which is great for Terminal Server scenario's and other.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;o:p&gt;&lt;font color="#800080"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;font color="#800080"&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif';"&gt;&lt;/span&gt;&lt;span style="font-family: 'Arial','sans-serif';"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=623831" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ashishme/archive/tags/.NET+Framework/default.aspx">.NET Framework</category></item></channel></rss>