Duty Hours

An application to record and report residents' duty hours.

Running the application

  1. Change the connection string in Web project's web.config. It's been tested with MS LocalDB but any flavor of SQL server should work.
  2. Run update-database from the package manager console. Be sure to target the DataAccess project. This will run the database migrations.
  3. Launch the application. The home page will list the users in the system. Clicking the link will run a duty analysis for that user and dispaly the results in the browser.

Application organization

The solution is organized to implement the onion architecture. That is to say that lower level abstractions should never depend on higher level abstractions. There is a core project that has as few dependencies as possible. Business domain objects, service interfaces, and BCL type extension methods could live here.

The next layer in the onion is the application project. This is where the implementation of business service interfaces could live. My preference is to separate business services into features. In this project, the "feature" is duty shift analysis and the folder structure reflects that.

Next is the Web project. The web project is really just the presentation layer. In a perfect world, no business logic should be performed in the presentation layer. Here, there's some query logic to get only the shifts for a specific user. This kind of thing would be better suited for the application layer.

Finally, there's the data access layer. The data access layer is actually special. It should lay outside of the onion altogether. In practice, it is a lower level dependency that should only be depended on by the application layer.

In terms of class structure, the SOLID principals act as my guideline. Practically, what that means is the duty shift analysis rules are each encoded into their own class that implement the same interface. This is an example of how the single responsibility principle (S in SOLID) can be applied.

Dependency inversion (D in SOLID) is accomplished through an inversion of control container, specifically Autofac.

The bits to pay attention to

  • Everything in the Application project
  • Data access except the Identity folder
  • The Tests project
  • startup.cs in web project
  • Duty analysis controller and accompanying view

I tried to mark autogenerated files at the top with a comment, but the VS scaffolding generates quite a bit of files. More or less, other than those listed above, the rest are generated.