Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > BOOK: Professional ASP.NET Design Patterns
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET Design Patterns
This is the forum to discuss the Wrox book Professional ASP.NET Design Patterns by Scott Millett; ISBN: 978-0-470-29278-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET Design Patterns section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 4th, 2010, 01:36 AM
Authorized User
 
Join Date: Jan 2006
Location: , , Canada.
Posts: 13
Thanks: 6
Thanked 1 Time in 1 Post
Default AppService -> Domain Service -> Repository

Hi,


I have a question regarding how the AppService layer should interact with the domain / repository layer.


I have finished chapter 3 & 4, and in Ch3, the GetAllProductsFor method calls the GetAllProductsFor method in the domain layer which in turn calls the repository, but in Chapter 4, GetAllBankAccounts directly calls the repository.


I am wondering why this is.. is it because we need to call the Apply method (the discount strategy) on the domain entity (list of Products) and we can't do it on the AppService layer?


Maybe the reason will be answered in later chapters.. but in case it won't, can you shed some light?
Reply With Quote
  #2 (permalink)  
Old November 4th, 2010, 04:51 AM
elbandit's Avatar
Wrox Author
Points: 599, Level: 8
Points: 599, Level: 8 Points: 599, Level: 8 Points: 599, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: Southsea, Portsmouth, Hampshire, United Kingdom.
Posts: 107
Thanks: 10
Thanked 17 Times in 15 Posts
Default

Hi Samvan,

Thanks for buying the book!

I don't go into real detail on the role of the application layer apart from the paragraph on page 92. For more information refer to Evans Domain Driven Design book or check out the following article: http://weblogs.asp.net/pgielens/arch...en-Design.aspx. In the book I use the application layer to convert domain entities into viewmodels (chapter 8) for the purpose of displaying in the UX.

Quote:
I am wondering why this is.. is it because we need to call the Apply method (the discount strategy) on the domain entity (list of Products) and we can't do it on the AppService layer?

Basically Yes. In chapter 3 the app service layer calls into the domain service, as the process of returning a list of products requires some business logic to be run (i.e. the working out of correct discount) and to my view this is a domain concern. In chapter 4 returning the list of bank accounts doesn't require any logic so it makes sense to go directly to the repository to return a list of all the accounts.

Hope that helps
Cheers
Scott

Please let me know what you think about the rest of the book or if you have any more questions.
Reply With Quote
The Following User Says Thank You to elbandit For This Useful Post:
samvan (November 4th, 2010)
  #3 (permalink)  
Old November 4th, 2010, 01:53 PM
Authorized User
 
Join Date: Jan 2006
Location: , , Canada.
Posts: 13
Thanks: 6
Thanked 1 Time in 1 Post
Default

Thanks for the info. I like the book very much (am reading Ch 5 on patterns).

One thing I am unclear about the app service layer: does "role-based authorization" fall into the realm of application service?

Consider this example:

the presentation layer needs to show/hide a Edit button based on a BlogPostResponse (w/ a bool CanEdit property) returned by the App Service layer.

Where should I put the logic to determine the CanEdit property? Should I determine the permission separately (see below) from the Blog Model and set the CanEdit property inside App Service?

The logic will be to compare the User.ID with the BlogPost.AuthorID and see if they match, and maybe see if the user is a global blog editor who has the right to edit all blog posts (e.g the User entity has a IsInRoleType(roleType.GlobalEditor) method ).
Reply With Quote
  #4 (permalink)  
Old November 4th, 2010, 04:10 PM
elbandit's Avatar
Wrox Author
Points: 599, Level: 8
Points: 599, Level: 8 Points: 599, Level: 8 Points: 599, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: Southsea, Portsmouth, Hampshire, United Kingdom.
Posts: 107
Thanks: 10
Thanked 17 Times in 15 Posts
Default

Fair point.

Maybe in this case the application service layer authenticates the user by extracting a user id from a cookie or from some other form of storage (not the concern of the domain). The app server would then query the repository for the user and then supply this to the domain to resolve whether the blog post can be edited. All of these things of course change depending on the type of system you are modelling and the domain rules.

This blog post from Jimmy Bogard details the uses of the various services from a DDD point of view. I use the application service in the same manner i.e. to facilitate message request and response.
http://www.lostechies.com/blogs/jimm...en-design.aspx.

Does that make it clearer?
Reply With Quote
  #5 (permalink)  
Old December 15th, 2011, 12:35 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Same Service Names in different layers.

Hi Scott,
I like what I have read so far only had it a day (along with Professional Enterprise .NET). I have been trying to apply much of what I have learn't in the past and these books are showing me how easily my development skills have become blunt.

Having read chapter 3, I have to say that Model.ProductService and Service.ProductService, does not feel right. Having read the blog post linked above, I now know the cause of the this discomfort, and it is purely down to naming.

I personally don't like Model.ProductService notation and feel that using a typedef (using newName = namespace.type) should only be used for classes that you have no naming control over (thirdparty libraries)

Wouldn't Model.ProductService better convey intent with a name such as ProductModelService ?... leaving ProductService in the Service namespace.

Incidently I wonder if the namespaces could have been named to better convey the layer they represent ? ....

Just my thoughs and I'm sure many will disagree.

Many Thanks for such a good book.

Regards
Mark
Reply With Quote
  #6 (permalink)  
Old January 13th, 2012, 08:18 AM
elbandit's Avatar
Wrox Author
Points: 599, Level: 8
Points: 599, Level: 8 Points: 599, Level: 8 Points: 599, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: Southsea, Portsmouth, Hampshire, United Kingdom.
Posts: 107
Thanks: 10
Thanked 17 Times in 15 Posts
Default

Hi Mark,

Thanks for buying the book and sorry for my late reply. You touch on a very important subject of naming, and you are right to pick up on the fact that Model.ProductService and Service.ProductService don't do a great job of describing exactly what they are doing. Perhaps a better method would have been to allow the Service.ProductService to pull all products required and then to use a Domain Service maybe better named ProductDiscountPolicy rather than Model.ProductService to apply discounts something like....

Service.ProductService

PHP Code:
public class ProductService
{
    private 
ProductDiscountPolicy _productDiscountPolicy;
    private 
IProductRepository _productRepository;
    
    public 
ProductService(ProductDiscountPolicy productDiscountPolicy
                          IProductRepository productRepository
)
    {
        
_productDiscountPolicy productDiscountPolicy;
        
_productRepository productRepository;
    }

    public 
ProductListResponse GetAllProductsFor(ProductListRequest productListRequest)
    {
       
ProductListResponse productListResponse = new ProductListResponse();
    
        try {
            
IList<Model.ProductproductEntities productRepository.FindAll();

            
// Applicatgion Service using the Domain Service, in this case named Product Discount Polcity
            
productListResponse.Products _productDiscountPolicy.ApplyDiscountToProducts(productEntitiesproductListRequest.CustomerType);

            
productEntities.ConvertToProductListViewModel();
            
productListResponse.Success true;
        }
            catch (
Exception ex)
        {
            
// Log the exception…
            
productListResponse.Success false;
            
// Return a friendly error message
            
productListResponse.Message = &#8220;An error occurred”;
        
}        
        return 
productListResponse;
    }

let me know what you think.
Cheers
SCott
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
<PLEASE HELP> Web Service norwild BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 4 October 23rd, 2007 07:03 AM
Chpt 7 >> Pg 245 >>Try It Out #4-5 harrison4411 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 March 2nd, 2006 06:26 PM
Achitecture ? SQL -> XML -> ASP -> PDF or HTML Frm jstrong Classic ASP XML 0 July 9th, 2005 01:18 PM
Chapter 4> ERROR using "=>>>" guiro BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 5 January 13th, 2005 06:38 PM
VB.Net -> Filename -> DTS Package -> tempdB daniel Pro VB.NET 2002/2003 1 October 7th, 2004 01:46 PM



All times are GMT -4. The time now is 06:04 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.