EcoController

Implementing support for an MVC Controller that uses an EcoSpace for persistence, the EcoController is the base class for all other MDriven controllers.

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

Without additions, it creates an EcoSpace with the type given when subclassing using a type specifier (EcoController<your ecospace type>). When the controller goes out of scope (i.e. the web page is returned to the client), the EcoSpace is disposed of.

TempData Used for "Shelving"

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.

On a broken redirect, i.e. the web browser doesn't complete the redirect to the new view - items will be left "shelved". EcoSpaces placed on the shelf will be disposed of or returned to the cache provider if they aren't unshelved within 1 minute. This is done by any subsequent controller using the same session. If the whole session is removed and a garbage collection occurs, shelved EcoSpaces will be disposed of or returned to the cache provider.

VMClass

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

Note that the redirect functions support passing your VMClass object to the new controller saving rendering time.

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 to controllers.
  • Subclass the class EcoSpaceRequestInfo and add the attributes 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 = <your ecospace provider>; // 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 <object with information to the cache provider>
}
This page was edited 172 days ago on 06/17/2024. What links here