-
Notifications
You must be signed in to change notification settings - Fork 3
Customizing the helpers
Since version v4.0.0 the helper file is not longer provided, but the personalization of the helpers implementation is still possible. This is the workaround to do it:
In case of a full personalization you can implement the interface MongoSessionStateStore.SessionHelpers.ISessionHelper in your own class.
If you want to personalize only some of the methods provided in the package, extend the class MongoSessionStateStore.SessionHelpers.SessionHelper and override those methods that you need. All methods of this class are declared as virtual, so you can rewrite every method that you want.
Once you have your own class you must load only one instance of this class when the application is loaded. To do that you have to call this provided method: System.Web.Mvc.MongoSessionUserHelpersMvc.SetHelper(new <YourPersonalizedClass>()); You should do it in the Application_Start event available in Global.asax.cs file.
Never call this method when the application is running (for example inside a Controller) because is not thread safe due the following reasons:
- To set helpers is only needed when the application is loaded (main reason).
- To make it thread safe has a cost in performance.
- A thread safe implementation is more complex.
The solution that test this personalization contains an example of how to do it. Here you'll find two personalized implementations: one for personalize some methods and other one for a full personalization. Here the implementation of InitSessionHelper and here the implementation of the application_start event that calls the InitSessionHelper.