Good way on creating C# validation class
I have a functionality that upload a file, validate it, save it to database and so on.
All of these actions are on some different classes and methods. But, if something goes wrong in any of these methods, I want to inform these errors to my front-end.
I开发者_如何学编程s there a good way to manage this, let's call, "Error Class"?
Thanks!
One approach that you could take would be to create the "Error Class" like a service in your application and post the different classes and methods that perform various actions could post errors to it.
Now your front-end can either subscribe with the "Error Class" to know of errors immediately or you could return an error code the details of which can be found using the "Error Class"
Well lets say, your sequence of processing a file is
- Upload
- Validate
- Save
- Return with success result/error.
Now, in all these sequence if its same all the time, then you could just go for exception throwing mechanism and collect it at the front end. May be you could throw with an Error ID.
精彩评论