﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Sly Gryphon commented on Don’t castrate your architecture</title><description>Some people just don't understand the difference between layers and tiers. Using a layered architecture is generally good, but that doesn't mean you need to run them on separate tiers (and in fact, it causes problems with performance and more). I've seen this problem before; I hope you sorted them out.
  
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment25</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment25</guid><pubDate>Tue, 11 Aug 2009 13:42:11 GMT</pubDate></item><item><title>Ayende Rahien commented on Don’t castrate your architecture</title><description>Niraj,
  
Actually, I don't mind overly much if you do the controller stuff directly in the WCF service, no.
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment24</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment24</guid><pubDate>Thu, 23 Jul 2009 18:24:04 GMT</pubDate></item><item><title>Niraj commented on Don’t castrate your architecture</title><description>Ayende,
  
  
         Normally we have the practice of clubbing WCF layer and Controllers (the usecase coordinator). We infact had no controller layer and WCF use to coordinate between the entities + transactions. Again I could have separated them but it was sort of creating a one to one mapping in both places. Do you have a something like stripper pattern (evaluating pros / cons) for this? We weren't creating a SOA style app.
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment23</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment23</guid><pubDate>Thu, 23 Jul 2009 12:01:54 GMT</pubDate></item><item><title>Lalit Kale commented on Don’t castrate your architecture</title><description>I think its better to have some demos of N-Tier best practices of "WCF and NHibernate" rather than talking in air.
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment22</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment22</guid><pubDate>Wed, 22 Jul 2009 10:42:55 GMT</pubDate></item><item><title>Peter commented on Don’t castrate your architecture</title><description>Ayende,
  
  
I would love to see more of your findings on WCF and NHibernate usage.
  
  
I recently started to use WCF and have been using nhibernate already for a fair amount of time.   There seem to be several hoops which the combination of the two technologies make you jump through, like where to put the session factory etc.
  
  
Would you do a few demo apps or more blog posts for how you would recommend the two technologies working together?   and where the common pitfalls are.  I think this would make the  NHibernate and WCF combination clearer to people, it would also help my understanding out immensely.
  
  
Thanks
  
Pete
  
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment21</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment21</guid><pubDate>Tue, 21 Jul 2009 14:53:51 GMT</pubDate></item><item><title>Ayende Rahien commented on Don’t castrate your architecture</title><description>Niraj,
  
Please note that I advocate this type of architecture for a multi tier applications only.
  
If it is just running on the same machine, things are different, but for multi tiers, yes, you ARE going to have to do something about it.
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment20</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment20</guid><pubDate>Tue, 21 Jul 2009 14:38:15 GMT</pubDate></item><item><title>Niraj commented on Don’t castrate your architecture</title><description>@Ayende, I get the point though WCF serializes only public part by default. But this is becoming crazy. I have entities layer, then I have DTO, and then if I am using something like MVVM like will have one more ViewModel. Lot of duplication :(. Anyways I will take it up in my next project with UI validation implemented inside ViewModel properties.
  
  
One more query in your post of UI should talk to DAL, you have a query wrapping business logic &amp; then high level components paginate it. But do you mean that I have to retrive all data in my App layer &amp; throw a window of it to presentation?
  
  
@lexx, I had used stateless singleton WCF implementation &amp; it worked well for me. And all the logic related to given data was consolidated in a single place &amp; assembly was shared (no add service reference - just IChannelFactory interface)
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment19</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment19</guid><pubDate>Tue, 21 Jul 2009 14:28:38 GMT</pubDate></item><item><title>Ayende Rahien commented on Don’t castrate your architecture</title><description>Peter,
  
See my post about the DAL why I don't really like the division into BL and DAL.
  
I consider it false way of doing thing. I would much rather have a single layer which handle BL and infrastructure bits around it.
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment18</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment18</guid><pubDate>Tue, 21 Jul 2009 13:42:19 GMT</pubDate></item><item><title>Ayende Rahien commented on Don’t castrate your architecture</title><description>cowgaR, 
  
Not really, a single request tend to do one thing, so you usually pack it into a DTO and send it to the backend, where it unpacks itself and do something meaningful.
  
The best description of that is from Udi:
  
[www.udidahan.com/.../entity-framework-disconnec...](http://www.udidahan.com/2007/03/30/entity-framework-disconnected-problems-solutions/)  
  
If you want to use NH builtin support for that, take a look at session.Merge
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment17</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment17</guid><pubDate>Tue, 21 Jul 2009 13:41:08 GMT</pubDate></item><item><title>Peter Morris commented on Don’t castrate your architecture</title><description>@Ayende.
  
  
The app layer *is* the business layer.  Talks DTOs externally, and then either manipulates business domain classes directly or via services.
  
  
By "business layer" I mean "application API" - not sure if we are using the same terminology or not.
  
  
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment16</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment16</guid><pubDate>Tue, 21 Jul 2009 13:37:50 GMT</pubDate></item><item><title>Peter Morris commented on Don’t castrate your architecture</title><description>@lexx
  
  
You might like AutoMapper.
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment15</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment15</guid><pubDate>Tue, 21 Jul 2009 13:34:56 GMT</pubDate></item><item><title>Nick Berardi commented on Don’t castrate your architecture</title><description>If anything is going to castrate your architecture, it is running your business of a Windows Home Sever.  :)
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment14</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment14</guid><pubDate>Tue, 21 Jul 2009 13:24:09 GMT</pubDate></item><item><title>cowgaR commented on Don’t castrate your architecture</title><description>that's why I put entity in parenthesis... but as far as I know it doesn't matter if it is DTO or entity, I still need to track changes down...
  
  
so, using NHibernate, and DTO, what is the recomended approach in asp.net mvc layer to communicate with application layer if detatched entities are not recommended solution?
  
  
  
thanks for answer
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment13</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment13</guid><pubDate>Tue, 21 Jul 2009 13:12:15 GMT</pubDate></item><item><title>Ayende Rahien commented on Don’t castrate your architecture</title><description>@lexx,
  
Yes, I want them to be separate classes.
  
Moreover, I want different classes for different scenarios.
  
CustomerForOrder is different than CustomerForLogin
  
If you care about the code to convert it, use AutoMapper, but it is really not much of a problem.
  
  
@Arild,
  
You don't push entities on the wires, and you don't do anything with them in the UI layer anyway, so there is no problem.
  
  
@Mike,
  
That really depend on too many variables to answer, but ideally, yes.
  
The web server would be mostly HTML generation and request handling, mostly out of local cache. The app server would handle request that require data or BL, and send them to the local cache of the web server.
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment12</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment12</guid><pubDate>Tue, 21 Jul 2009 13:01:11 GMT</pubDate></item><item><title>Ayende Rahien commented on Don’t castrate your architecture</title><description>cowgaR,
  
NH does have support for detached entities, it is just not a recommended approach.
  
As for the image, I agree it is ridiculous.
  
I wouldn't pass entities around, the UI deals with DTOs, never entities. Also, note that we are talking about tiers vs. layers, that is an important distinction
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment11</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment11</guid><pubDate>Tue, 21 Jul 2009 12:58:22 GMT</pubDate></item><item><title>Ayende Rahien commented on Don’t castrate your architecture</title><description>Niraj,
  
No! Yuck, you don't want to share entities on the wire, see the stripper pattern post about why.
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment10</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment10</guid><pubDate>Tue, 21 Jul 2009 12:56:04 GMT</pubDate></item><item><title>Ayende Rahien commented on Don’t castrate your architecture</title><description>Peter,
  
In general, I agree about the DTO, but I am not sure that I agree with hiding the BL in any way.
  
The app tier tend to talk in DTOs externally, and entities internally.
  
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment9</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment9</guid><pubDate>Tue, 21 Jul 2009 12:54:52 GMT</pubDate></item><item><title>Mike commented on Don’t castrate your architecture</title><description>Just to clarify, you'd use WCF to expose an API from the Application Server to the Web Server and keep the web server solely for handling requests?
  
  
Thanks,
  
  
Mike
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment8</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment8</guid><pubDate>Tue, 21 Jul 2009 12:24:27 GMT</pubDate></item><item><title>lexx commented on Don’t castrate your architecture</title><description>@ Peter,
  
In case we have separate classes we will have to copy data transferred from DataContract to entity in order to manipulate entities in the App Server. This sounds like a duplicate code. Don't you agree?
  
@ Niraj,
  
Mostly agree.  Are you using session per request on the App Server side? Have you tried this kind of architecture on the high loaded apps?
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment7</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment7</guid><pubDate>Tue, 21 Jul 2009 12:10:58 GMT</pubDate></item><item><title>cowgaR commented on Don’t castrate your architecture</title><description>__“that is how we do things”
 is number 4 practice of the guide "how to beat a dead horse" :)
  
  
but the guy may have its own truth, because once you start building SOA applications, you DO need some kind of seperation, although the picture portraied is really ridiculous.
  
  
I think it is harder to do with NHibernate (although it is an awesome framework, congratz to 2.1!) but there are some, like LLBLGen, which offers change tracking inside entities, thus serializing them and transfering on wire isn't such a serious problem.
  
And lazy loading is a dangerous thing this way or that way :)
  
  
Btw, I don't see solution either in your picture, how would you transfer "entity" from the UI layer back to your Application Server layer if not using services? How would you track changes? Just asking, we both know who's guru here :)
  
  
Care to elaborate more? btw EXCELLENT post, I would really welcome more on this topic!
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment6</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment6</guid><pubDate>Tue, 21 Jul 2009 12:10:16 GMT</pubDate></item><item><title>Niraj commented on Don’t castrate your architecture</title><description>@lexx, generally it's not required. Infact DTO's created would club many entities together. Some people seperated DTO from entities because of .NET attributes imposed by WCF but that also I guess is no longer mandatory with .NET 3.5 SP1. Infact I would suggest you to share the entire Entity layer assembly with your presentation which would help you consolidate your validation logic as well (unless you are in a SOA mode).
  
  
@Arlid, I agree with you. Normally a single server should suffice (and is best in terms of performance, etc.) unless your Security requirements mandate it.
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment5</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment5</guid><pubDate>Tue, 21 Jul 2009 11:21:24 GMT</pubDate></item><item><title>Steve commented on Don’t castrate your architecture</title><description>Arild: He is meaning lazyload/caching from the App to database.  (WCF at the App level, NHibernate used 'behind' the WCF interfaces)
  
  
  
  
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment4</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment4</guid><pubDate>Tue, 21 Jul 2009 11:15:43 GMT</pubDate></item><item><title>Arild commented on Don’t castrate your architecture</title><description>In the suggested solution, I'm assuming WCF is used for communication between the web server and the app server. Don't you run into some of the same problems with lazy loading and caching there?
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment3</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment3</guid><pubDate>Tue, 21 Jul 2009 09:20:34 GMT</pubDate></item><item><title>Peter Morris commented on Don’t castrate your architecture</title><description>Depends on how complex the business layer is really.  If it is very complex then you might need to hide the structure of the domain classes behind an app layer; but the important thing is that you talk in application API (data transfer objects) rather than instances of domain classes.
  
  
The DTOs will not only have all required data loaded but will not have any properties there which aren't required for the specific use case; preventing someone from "just using the one that is already there to do something else" - which would run you into lazy load problems because the object is not connected to a session.
  
  
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment2</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment2</guid><pubDate>Tue, 21 Jul 2009 09:09:54 GMT</pubDate></item><item><title>lexx commented on Don’t castrate your architecture</title><description>Ayende, when we deal with WCF we have Data Contracts for DTO and at the same time we have domain model and entities in our App Server. Lets say we have a customer entity and a customer datacontract. 
  
The fields of this classes will mostly be the same.
  
Do you suggest anyway to have them as separate classes?
</description><link>http://ayende.com/4071/don-t-castrate-your-architecture#comment1</link><guid>http://ayende.com/4071/don-t-castrate-your-architecture#comment1</guid><pubDate>Tue, 21 Jul 2009 08:28:01 GMT</pubDate></item></channel></rss>