Skip to content

Commit dc6ff25

Browse files
committed
Working towards DI compat by allowing developpers to set their own IActionSettingsSerialiser.Serialiser value.
1 parent e6fdf30 commit dc6ff25

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

DevTrends.MvcDonutCaching/HtmlHelperExtensions.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@ namespace DevTrends.MvcDonutCaching
66
{
77
public static class HtmlHelperExtensions
88
{
9-
private static readonly IActionSettingsSerialiser Serialiser = new EncryptingActionSettingsSerialiser(new ActionSettingsSerialiser(), new Encryptor());
9+
private static IActionSettingsSerialiser _serialiser;
10+
11+
public static IActionSettingsSerialiser Serialiser
12+
{
13+
get
14+
{
15+
return _serialiser ?? (_serialiser = new EncryptingActionSettingsSerialiser(new ActionSettingsSerialiser(), new Encryptor()));
16+
}
17+
set
18+
{
19+
_serialiser = value;
20+
}
21+
}
1022

1123
/// <summary>
1224
/// Invokes the specified child action method and returns the result as an HTML string.
@@ -79,7 +91,7 @@ public static MvcHtmlString Action(this HtmlHelper htmlHelper, string actionName
7991
/// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
8092
/// <param name="actionName">The name of the child action method to invoke.</param>
8193
/// <param name="excludeFromParentCache">A flag that determines whether the action should be excluded from any parent cache.</param>
82-
94+
8395
public static void RenderAction(this HtmlHelper htmlHelper, string actionName, bool excludeFromParentCache)
8496
{
8597
RenderAction(htmlHelper, actionName, null, null, excludeFromParentCache);
@@ -92,7 +104,7 @@ public static void RenderAction(this HtmlHelper htmlHelper, string actionName, b
92104
/// <param name="actionName">The name of the child action method to invoke.</param>
93105
/// <param name="routeValues">A dictionary that contains the parameters for a route. You can use routeValues to provide the parameters that are bound to the action method parameters. The routeValues parameter is merged with the original route values and overrides them.</param>
94106
/// <param name="excludeFromParentCache">A flag that determines whether the action should be excluded from any parent cache.</param>
95-
107+
96108
public static void RenderAction(this HtmlHelper htmlHelper, string actionName, object routeValues, bool excludeFromParentCache)
97109
{
98110
RenderAction(htmlHelper, actionName, null, new RouteValueDictionary(routeValues), excludeFromParentCache);
@@ -175,7 +187,7 @@ public static MvcHtmlString Action(this HtmlHelper htmlHelper, string actionName
175187
{
176188
var serialisedActionSettings = GetSerialisedActionSettings(actionName, controllerName, routeValues);
177189

178-
return new MvcHtmlString(string.Format("<!--Donut#{0}#-->{1}<!--EndDonut-->", serialisedActionSettings, htmlHelper.Action(actionName, controllerName, routeValues)));
190+
return new MvcHtmlString(string.Format("<!--Donut#{0}#-->{1}<!--EndDonut-->", serialisedActionSettings, htmlHelper.Action(actionName, controllerName, routeValues)));
179191
}
180192

181193
return htmlHelper.Action(actionName, controllerName, routeValues);

0 commit comments

Comments
 (0)