Skip to content

Commit

Permalink
Merge branch 'master' into proxy-writing
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	ReferenceWebsite/App_Data/Umbraco.sdf
#	UmbracoVault/UmbracoVault.nuspec
  • Loading branch information
Kaleb Luhman committed Oct 25, 2016
2 parents 952fe27 + 9a43f44 commit 1b785d1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Fixes issue where proxied models created from IContent models did not support recursive hydration.
* Fixes issue where if a proxy property was overwritten with some value not from CMS, it would not persist and would still use CMS value.
* Fixes issue where preview content breaks due to use of a singleton UmbracoHelper. [#34]

## v1.3.0

Expand Down
Binary file modified ReferenceWebsite/App_Data/Umbraco.sdf
Binary file not shown.
42 changes: 42 additions & 0 deletions UmbracoVault/Extensions/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace UmbracoVault.Extensions
{
internal static class DictionaryExtensions
{
public static object GetOrAddThreadSafe(this IDictionary dictionary, object key, Func<object, object> valueFactory)
{
if (!dictionary.Contains(key))
{
lock (key)
{
if (!dictionary.Contains(key))
{
dictionary.Add(key, valueFactory(key));
}
}
}

return dictionary[key];
}

public static object GetOrAddThreadSafe(this IDictionary dictionary, object key, object value)
{
return dictionary.GetOrAddThreadSafe(key, k => value);
}

public static T GetOrAddThreadSafe<T>(this IDictionary dictionary, object key, Func<object, T> valueFactory)
{
var factoryWrapper = new Func<object, object>(k => valueFactory(k));
return (T)dictionary.GetOrAddThreadSafe(key, factoryWrapper);
}

public static T GetOrAddThreadSafe<T>(this IDictionary dictionary, object key, T value)
{
return dictionary.GetOrAddThreadSafe(key, k => value);
}
}
}
10 changes: 8 additions & 2 deletions UmbracoVault/UmbracoContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Web;

using Umbraco.Core;
using Umbraco.Core.Logging;
Expand All @@ -28,8 +29,7 @@ public class UmbracoWebContext : BaseUmbracoContext
//new SuperScriptTransformation()
};

private UmbracoHelper _helper;
protected UmbracoHelper Helper => _helper ?? (_helper = new UmbracoHelper(UmbracoContext.Current));
protected UmbracoHelper Helper => GetUmbracoHelperForRequest();

private IPublishedContent GetCurrentUmbracoContent()
{
Expand Down Expand Up @@ -166,6 +166,12 @@ protected T GetItem<T>(IPublishedContent n)
return result;
}

private static UmbracoHelper GetUmbracoHelperForRequest()
{
const string umbracoHelperKey = "__vaultUmbracoHelper";
return HttpContext.Current?.Items.GetOrAddThreadSafe(string.Intern(umbracoHelperKey), new UmbracoHelper(UmbracoContext.Current));
}

public static ReadOnlyCollection<string> GetUmbracoEntityAliasesFromType(Type type)
{
var results = new HashSet<string>();
Expand Down
1 change: 1 addition & 0 deletions UmbracoVault/UmbracoVault.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<Compile Include="Controllers\VaultDefaultGenericController.cs" />
<Compile Include="Controllers\VaultRenderMvcController.cs" />
<Compile Include="Exceptions\VaultNotImplementedException.cs" />
<Compile Include="Extensions\DictionaryExtensions.cs" />
<Compile Include="Extensions\ObjectExtensions.cs" />
<Compile Include="Models\NamedItem.cs" />
<Compile Include="Proxy\ILazyResolverMixin.cs" />
Expand Down
1 change: 1 addition & 0 deletions UmbracoVault/UmbracoVault.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<releaseNotes>
* Fixes issue where proxied models created from IContent models did not support recursive hydration.
* Fixes issue where if a proxy property was overwritten with some value not from CMS, it would not persist and would still use CMS value.
* Fixes issue where preview content breaks due to use of a singleton UmbracoHelper. [#34]
</releaseNotes>
<copyright>(c) The Nerdery LLC 2016. All Rights Reserved.</copyright>
<tags>Umbraco UmbracoVault Mapping ObjectMapper ORM CMS</tags>
Expand Down

0 comments on commit 1b785d1

Please sign in to comment.