I have created an MVC application that looks like this:
I have read the code of applications and found that no one passes the exception in the manner that the data is passed. In other words, the data is referenced through the interface and is reused in different contexts. If there is an exception in the data layer, how will it be sent to the GUI or the relevant layer? Should an Interface Be Used? What is the construction of the application to handle the exception? I read did not doco U link, but I have a simple case where I meet a immutability I take exceptions in response to the failure. It is said that I am making an example and for some reason it is "invalid", suppose bad user input instead of being in an invalid state (which is not a number-number in DDD) and my system is "valid" "Let it be, when it is being made, throws an exception. The relevant "verification message" (for the user) is exempt from the same specificity example that was not satisfied and my derived exception value is included in the need for UI. Example An example of a specificity that gives the relevant "verification message" to the user / UI: An example of how the factory has never created an invalid example, instead it throws an exception and collects the message for the UI: Finally, the example of a custom model binder that is used to catch an exception and "invalid object" is used to return the action with error messages Public class PostModelBinder: PublicModelBinder {public override object BindModel (ControllerContext controllerContext, ModelBindingContext bindingContext) {if (bindingContext.ModelType == typeof (post)) {try {/ Create / return postback basis .Bind Modal (Controller Contubebox, Binding Conttexttech); } Hold (InvariantException ie) {// If it is invalid, then the ModelState binding consort from the factory. ModelState. Add Errors to AddNewErrors (ie.ModelState); BindingContext.ModelState.AddValuesFor & LT; Post & gt; (BindingContext.ValueProvider); That means return FailingObject; }} Hope it helps. MVC application - application Layer - business layer - repository - data
InvariantException :
public class unrealistic exception: MyAppException {public object FailingObject = null; Public ModelStateDictionary ModelState = New ModelStateactive (); Public InvariantException () {} Public InvariantException (Object Failed Object, ModelStateDictionary Message) {this.FailingObject = failingObject; This.ModelState = Message; } Public InvariantException (object failingObject, ModelStateDictionary messages, exceptions InnerException): base (InnerException mentioned "ModelState";) {ThiskFailingObject = FailingObject; This.ModelState = Message; }}
public class Postfill Lengality Explanation: ISpecification & lt; Post & gt; {Private contact string TITLE_LENGTH_RANGE = "5-100"; Private cast string BODY_LENGTH_RANGE = "20-10000"; Public Bull istiffidby (post post) {return it. GetArwers (Post) .IsValid; } Public ModelStatched GetErrors (Post Post) {ModelStateDictionary modelState = New ModelStateDictionary (); If modelState.AddModelError (StongTypeHelpers.GetPropertyName ((Post p) = & gt (post.Title.Trim () Length.Within (TITLE_LENGTH_RANGE) !.); p.Title), "Please let the characters Title {0} length In "(TITLE_LENGTH_RANGE). If modelState.AddModelError (StongTypeHelpers.GetPropertyName ((Post p) = & gt (post.BodyMarkup.Trim () Length.Within (BODY_LENGTH_RANGE) !.'s); p.BodyMarkup), "Please make sure you post {0} characters Is in length ". (BODY_LENGTH_RANGE); Return modelstate; }}
public static post GetNewPost (string title, string bodyMarkup DATETIME, post) {var post = new Post (0, title, BodyMarkup, post, a new list of & lt; comment & gt; ()); Var FieldLempanSpec = New Postfilst Langeline Display (); If (field lannetspace. Unsatisfied (post)) after the return; Other new inventors throw exceptions (post, field lengthspace. Gateearrs (post)); }
Comments
Post a Comment