Reputation: 364
I’ve inherited an ASP.NET (4.6.1) MVC solution that uses Entity Framework (database first) as its data access. All of the dbcontext
calls and all of the business logic is in the controller methods. There are no domain models.... only view models and the generated entity models from EF.
So the solution structure is basically:
At the very least, I want to isolate my DAL from my presentation layer and clean up my controllers. I'm not trying to create the perfect app... but I want to make incremental improvements. So my goal this round is to create a logical structure.
So I’m adding another project in between Web and DAL (called Service or whatever) and I'm moving all of the dbcontext calls/logic into that layer. I'm adding another project (called Core) to hold some DTOs, custom exceptions, and other goodies.
So this is my current solution:
Web (MVC web proj with Autofac)
Core (not to be confused with .NET Core)
Service
var result = dbcontext.SomeTable where some id = n...blah blah
)DAL
So I'm keeping the auto generated dbcontext in the DAL, moving the generated entity objects to Core so Service can see them.
My questions:
Does it make sense to move all of the dbcontext calls/logic out of the controllers and into the Service? Some of the logic is simple but there are several controller methods that have complex business logic in them as well. I'm just not sure where to put this logic/calls to dbcontext.
Does the overall solution design seem OK or am I making it to complex? It's a medium size app but it has potential to grow and I want to set myself up for future development.
Thanks for reading...any input is appreciated!
Upvotes: 1
Views: 350