asp.net mvc - Which data layer / handling architecture or pattern to choose for a non-enterprise web application? (MVC / EF) -
I want some help in designing for my application. This is a fairly straightforward web application, certainly the enterprise class or enterprise -nothing.
Architecture is standard MVC 5 / EF 6 / C # ASP.NET, and pages talk to back-end databases in SQL Server, and VS with all tables. EF Designer and I do not think change anytime in the near future. So the super essence is creating "what happens if my database changes" etc. Separation is probably meaningless; I am an operation of one person so that we can not talk to big teams.
What do I want to do is a clean way of doing CRUD and query operations on my database, and LINQ operations - but I'm not good with database related code design here are my approaches < / P>
Fixed class with 1 methods - I should create a stable class (my DAL) which keeps my datacentext and then provides the function that the controller can call directly < / P>
ud D. MyStaticDBLib.GetCustomerById (id)
But when we try to update the records with disconnected instances (ie I create an object with a JSON response and my table is' Update '). The good thing is that I can centralize my operation in Lib or DAL files. It's also complicated and messing up, because I can not create methods for every scenario, so I end up with the bits of the LINQ code in my controllers, and the bits controlled by these Lib methods
2. The square with reference is organized in a singleton, and is called the controller
MyContext _cx = MyStaticDBLib.GetMyContext ("sessionKey"); Var xx = cx.MyTable.Find (ID); // and other LINQ operations
This seems a bit dirty because my data query code is now in my controllers, but at least I have a clear reference for each session. Here's another idea. That LINQ-to-SQL already intimates the data layer to some degree, unless the institutions remain the same (the actual store can change), why not do so?
3. Use a general store and unit format pattern - Now we are getting fancy. I have read something about this method, and there are so many different suggestions, in which some strongly suggest that EF 6 has already created the repository in its reference, so it is overwork etc. It feels overwhelming, but I need to tell that reference to me
4 Something else? Basic database / CRUD / CRUD
Now I have a library type approach (1 above) and it is becoming increasingly messy. I have read many articles and I am struggling because there are many different perspectives, but I hope that the context I have given can get some reactions as per my approach that I can make it easy Need to keep, and I am a one-person-operation for the near future.
Not exactly the reference thread # 1 is not secure and you definitely have a static class in it Do not want as hostile enemies. You are just asking for your application to explode.
Option 2 works until you make sure your singleton thread is secure. In other words, it will be a singleton per-thread, not for the entire application. Otherwise, the same problems apply with # 1.
Option 3 is normal but short-distributed. Due to the ORM, the repository / unit of work pattern is very high. Wrapping the unit framework in the second layer, leaving only several advantages of working with the unit framework, as well as in developing your application. Increasing friction. In other words, it is lost and completely unnecessary.
So, I'll go with # 4 if the app is quite simple, then use your reference directly to deploy a container to inject your reference in the controller and request it-Skip (new theme Per request). If the application becomes more complicated or you really do not really care for dependence on the Entity Framework, then apply a service method, where you expose the endpoint for specific applications that your application requires it occurs. Put your references in the service class (es) and then include your service (s) in your controllers. Indication: The complete points of your service should return the data that are completely querying the database. (Such as return lists and similar calculators, not queries).
Comments
Post a Comment