tdshipley / CodingMonkey

A web application for learning C# by completing code exercises
2 stars 0 forks source link

Refactor Controllers into a CQRS pattern. #51

Closed tdshipley closed 7 years ago

tdshipley commented 8 years ago

Its not a must have but would be nice to use the Command Query Responsibility Segregation (CQRS) pattern to move my logic from my controllers (which would then only have the responsibility of routing requests) into Commands and Queries. There is a good overview here: CQRS with Mediator and Automapper And also a nice more detailed write up of the hows and whys here: Put Your Controllers on a Diet

The reason for doing all this is my logic would turn into simple classes which will be easier to unit test as I won't need to mock the different parts of the ASP.NET framework I am using.

tdshipley commented 8 years ago

I have added Automapper in PR #52 which would be the first part of this. I am still not sure however if I should use mediatR or not - more details are in the PR.

tdshipley commented 8 years ago

Decided not to do this for now - as I have added a Repository class for data which handles the in memory cache and the DB. With this layer of abstraction I think for now my controllers are thin enough. As the app increases in complexity this might be something to revisit so moving to backlog rather than closing for now.

no1melman commented 7 years ago

Noooooooooooooooooooo repository class LOL I think you would still benefit from introducing MediatR