Preopulate MVC Models with IOC - an alternative to caching?

I am considering strategies for a simple CMS implementation for an ASP.NET MVC site. The simple part is that I abstracted the values ​​used in various partial representations, all of which are user controls that have the same CSS layouts. Therefore, I populate user values ​​in identical partial views from the database, where I can sometimes change them using CRUD.

The not so simple part is a fairly efficient and logical abstraction of a standard user interface element as rows of a sql table. But putting that aside ...

I know that I am going to use some supermodels to pass preconfigured models for partial views to each page. But if they are preconfigured and preloaded, where to put them before the call?

The part that makes me think I'm a little crazy to go this route is the load time for what is essentially static data. But then again, SharePoint!

So (I think) why not load it all into application_start? Why not? I answer! Then I use IoC for something that google returns more than one link to good information from even one smart person who has ever thought that this could be a reasonable idea.

And does anyone have a better idea of ​​populating a model from a database using an IoC container other than placing a repository call in the constructor?

And then, does anyone think that putting these static data models in an IoC container accessible to controllers is a dumb idea?

Thanks,

S. Machino

+3
source share
2 answers

Following a few SOLID principles, keep your things as purposeful as possible. For semi-static data, first create a repository that loads this data. This will load data for each request. It works, but probably does not work so well, but now you have the implementation that you need.

, , - . CachingRepository , .

, .

CachingRepository Singleton, , , .

+3

, OutputCache . , , .

, , .

+1
source

Source: https://habr.com/ru/post/1724937/


All Articles