EcoController
(Created page with "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 E...")
 
No edit summary
Line 5: Line 5:
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.
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 =====
===== 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.
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.
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, that is, the web browser don't complete the redirect to the new view, items will be left "shelved". EcoSpaces placed on the shelf will be disposed 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 or returned to the cache provider.


===== VMClass =====
===== 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.
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.
Note that the redirect functions support passing your VMClass descendant along to the new controller saving rending time.


===== To add an EcoSpace cache provider =====
===== To add an EcoSpace cache provider =====

Revision as of 22:11, 7 July 2017

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 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, that is, the web browser don't complete the redirect to the new view, items will be left "shelved". EcoSpaces placed on the shelf will be disposed 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 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 build in support for validation updating the ModelState of your view.

Note that the redirect functions support passing your VMClass descendant along to the new controller saving rending time.

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 99 days ago on 02/10/2024. What links here