The following is more than just a lab exercise! There are many gems of insight into how S#arp Architecture is structured, motivations behind why it is designed the way it is, and insight into how to leverage it best.
Keep in mind that almost always, you would use the CRUD scaffolding generator as a starting point, which is discussed in detail in the next major section, but the lab which follows helps illustrate how the various layers work together by going through a bit of the process manually. The tutorial details all steps necessary for creating a new domain object and showing associated records from a database onto a web page. It covers creating the domain object, creating and testing the controller with mock objects, extending a data access object with a custom method, configuring repositories for dependency injection and displaying the results on a web page.
EditTest Driven Development Cycle
The following test-driven cycle will be followed while going through the tutorial steps:
- Write your test as if the target objects and API already exists.
- Compile the solution and see it break.
- Write just enough code to get it to compile.
- Run the test and see it fail.
- Write just enough code to get it to pass.
- Run the test and see it pass!
- Refactor if necessary!
For the purposes of this example, the user story is as follows:
Users may search for staff members matching a name filter. The results should include any staff members with a first name, last name, or employee number containing the provided filter.
dissertation helpEditTutorial Steps
Assume that we haven’t yet tackled another user story defined as "User may create staff member having a unique employee number" yet; so although not necessary yet, because it’s not dictated in the current user story that we’re tackling, let’s keep in mind that the staff member’s employee number is what makes it unique. With that said, let’s start with the domain model to support the staff member.
- Developing The Staff Member Domain Model
- Enabling The Domain Object For Comparison
- Developing the controller to Retrieve and Display Results
- Wiring Up Persistence Support
- Retrieving Results via a Custom Dao
- Showing the Results in a View
EditSo What Was Accomplished?
The above tutorial has taken us through a test driven approach of designing a domain model, creating a controller which uses a custom Repository, testing with a mock database, testing custom data access methods against an in-memory SQLite database, interacting with a live database, and displaying results in an MVC view. There’s plenty more to learn, but this covers the basics.
Don’t forget, as will be discussed next, that a CRUD scaffolding generator (see
Visual Studio Templates and Code Generation) is also available to create the entity, controller and views with very little effort. While this tutorial did not leverage the generator, for pedagogical reasons, the CRUD scaffolding generator is your friend and is a great starting point when you need to add a new domain entity. Also don’t forget that the scaffolding templates are completely customizable to meet your projects needs... enjoy!
essay help