Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

Exception/MessageBox in Calibur.Micro -


i start learning caliburn.micro , little confuse of handling exception/messange box in view model class.

i found blogs about, example:

http://frankmao.com/2010/11/18/handling-messagebox-in-caliburn-micro/

for example method in view model class can produce exception.

    public void methodwichcanproduceex(string arg1, string arg2 )     {         if(arg1==null)             throw new argumentnullexception("arg1 null");         if (arg2 == null)             throw new argumentnullexception("arg2 null");          try         {          }         catch (exception exception)         {              throw exception;             //? show message box messagebox.shox(exception.message)         }     } 

what correct handling , showing these exception in view ? exist kind of pattern caliburn.micro?

it possible trace exception in .net in text, xml file ?

for example trace exception in xml, text file , in view show message.box or message.

thank advance, maybe question little stupid, sorry learning calibur.micro.

you'll want work against abstractions in view models, in case of message boxes, don't want have wait user input when come unit test view models.

the frank mao code linked uses delegate abstract implementation of message box view model, use interface here. can think of delegate interface single method, advantage of using interface in context can have different methods depending on type of message wish show. example, have showmessageerror, showmessagewarning, showmessageinfo etc.

so, define contract message box:

public interface imessagebox {   void showexception(exception exc); } 

inject message box dependency view model, e.g. via constructor

public class myviewmodel {   private readonly imessagebox messagebox;    public myviewmodel(imessagebox messagebox)   {     this.messagebox = messagebox;   }    public void methodthatcanthrowexception()   {     try {}     catch(exception exc)     {       // log exception here       ...       // show message box       this.messagebox.showexception(exc);     }   } } 

you can implement message box anyway wish, either using windows system message box, or nicer still use own view/viewmodel display message, perhaps using caliburn.micro windowmanager.showdialog().

an implementation uses windows system message box may like:

public class standardmessagebox : imessagebox {   public void showexception(exception exception)   {     messagebox.show(exception.tostring(), "error occurred");   } } 

in production code, can register standardmessagebox against imessagebox interface in ioc container.

in unit test land, can mock out imessagebox , have nothing, or in case of methods result message box, return value wish.

for logging exception, @ logging framework such log4net (http://logging.apache.org/log4net/index.html) or nlog (http://nlog-project.org/)


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -