How Do You Communicate Service Layer Messages/Errors to Higher Layers Using MVP?

后端 未结 3 1523
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 01:17

I\'m currently writing an ASP.Net app from the UI down. I\'m implementing an MVP architecture because I\'m sick of Winforms and wanted something that had a better separation

3条回答
  •  佛祖请我去吃肉
    2020-12-13 02:02

    In reply to the follow-up question:

    As for creating exceptions becoming tedious, you kinda get used to it. Use of a good code generator or template can create the exception class with minimal hand editing within about 5 or 10 seconds.

    However, in many real world applications, error handling can be 70% of the work, so it's all just part of the game really.

    As tgmdbm suggests, in MVC/MVP applications I let all my unhandlable exceptions bubble up to the top and get caught by the dispatcher which delegates to an ExceptionHandler. I set it up so that it uses an ExceptionResolver that looks in the config file to choose an appropriate view to show the user. Java's Spring MVC library does this very well. Here's a snippet from a config file for Spring MVC's Exception resolver - its for Java/Spring but you'll get the idea.

    This takes a huge amount of exception handling out of your presenters/controllers altogether.

    
    
      
        
          
            rescues/UserNotFound
          
          
            rescues/databaseProblem
          
          
            rescues/networkTimeout
          
          
            rescues/validationError
          
          
            rescues/environmentNotConfigured
          
          
            rescues/messageRejected
          
        
      
      
    
    

提交回复
热议问题