EcoController

Implements support for a MVC Controller that uses an EcoSpace for persistence. The EcoController is the base class for all other MDriven controllers.

Includes support for a EcoSpace cache provider and a mechanism that stores the EcoSpace on TempData during redirect.

Without additions it creates an EcoSpace with the type specified on creation. When the controller goes out of scope (i.e. the page is returned to the client) the EcoSpace is disposed.

TempData use during redirect

When your controller redirects to a new page, use the function ShelveEcoSpace() to temporarily place the active EcoSpace on TempData. The "shelfkey" is usually the pagename and id combined.

The controller instantiated as a result of the redirect then uses UnshelveEcoSpace(), or even simpler, EnsureEcoSpace() on controller creation with the shelfkey passed as route values to the new controller.

VMClass

The EcoController also supports subclasses of VMClass to be used as the controller "model". If you use this for your views, you get build in support for validation updating the ModelState of your view.

To add an EcoSpace cache provider
  • Implement the interface IEcoSpaceCacheProvider on the class you use for the cache mechanism.
  • The IEcoSpaceCacheProvider should work with objects of a class implementing IEcoSpaceCacheWrapper. You add information in your wrapper to provide the best cached EcoSpace.
  • Subclass the class EcoSpaceRequestInfo, add attributes that you need for your cache provider. Your cache provider will serve requests using the information in EcoSpaceRequestInfo objects.
  • Subclass EcoController and set EcoSpaceProvider , like this;
public TurnkeyController_Base() : base()
{
  EcoSpaceProvider = TurnKeyEcoSpaceCreator.Singleton; // Install the cache/EcoSpace -provider (one for the entire application)
}
  • Also override GetEcoSpaceRequestInfo() in EcoController and provide the EcoSpaceRequestInfo when called.
protected override EcoSpaceRequestInfo GetEcoSpaceRequestInfo()
{
  return xxxx // You request object, passed to your cache provider
}
This page was edited 96 days ago on 02/10/2024. What links here