What is the best practice to persist data across controllers actions ??? RRS feed

  • Question

  • User-973886032 posted

    hi guys

    in my previous projects, I had used inherited controllers to persist data across my last project e.g. 

        public class UsersController : ProjectAController

    Although I added custom data to the base controller, e.g. shopping cart, alerts, statistics  etc

    These values are values that are loaded in the _Layout page (and are loaded once from the database, instead of repetitive round trip coding

    What is best practices ?



    Saturday, July 20, 2019 11:15 PM

All replies

  • User711641945 posted

    Hi afrika,

    I suggest that you could share the same database with the two projects.

    Take a shopping cart as an example, in ProjectA  controller,each time you add/delete a product, you could store/delete a record into your database.Then you could  get the product list  from the same database in the ProjectB.CartController.

    Best Regards,


    Monday, July 22, 2019 7:43 AM
  • User753101303 posted


    The best practice is to use what best fit your need rather than to apply blindly some kind of general recipe. See https://docs.microsoft.com/en-us/aspnet/core/fundamentals/app-state?view=aspnetcore-2.2 and then  it depends on which freshness/location/lifetime you need.

    For example first do you want the user to see the same information on its next sesssion  ? Then you should anwyay store this in a db (which doesn't prevent to use caching or whatever).

    Monday, July 22, 2019 8:26 AM