Skip to content

Commit

Permalink
Merge pull request #36 from kluhman/preview-support
Browse files Browse the repository at this point in the history
Preview support
  • Loading branch information
NerderyMGlanzer authored Oct 25, 2016
2 parents 5851343 + 33d553e commit abfb615
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 15 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<<<<<<< HEAD
## v1.3.1

* Fixes issue where preview content breaks due to use of a singleton UmbracoHelper. [#34]

## v1.3.0

**New Feature: Independence from Web Context**
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
11 changes: 1 addition & 10 deletions UmbracoVault/UmbracoVault.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,7 @@
<description>Vault for Umbraco is an easy-to-use, extensible ORM to quickly and easily get strongly-typed Umbraco CMS data into your views. It allows you to create lightly-decorated classes that Vault will understand how to hydrate. This gives you the full view model-style experience in Umbraco that you are accustomed to in MVC, complete with strongly-typed view properties (no more magic strings in your views).</description>
<summary>Vault for Umbraco is an easy-to-use, extensible ORM to quickly and easily get strongly-typed Umbraco CMS data into your views.</summary>
<releaseNotes>
**New Feature: Independence from Web Context**

Extended the current UmbracoContext implementation to include a secondary implementation that removes any dependency
on `IPublishedContext`, `UmbracoHelper`, and the Umbraco WebContext. Instead of using the WebContext as a vehicle
for retrieving data from Umbraco, the [ServiceContext](https://our.umbraco.org/documentation/Reference/Management/Services/)
is used. [#27]

**Other**

* Added `PropertyInfo` parameter to `FillClassProperties` to support additional behavior for libraries that extend Vault.[#25]
* 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
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
environment:
CURRENT_VERSION: 1.3.0
version: 1.3.0-{build}
CURRENT_VERSION: 1.3.1
version: 1.3.1-{build}
os: Visual Studio 2015
assembly_info:
patch: true
Expand Down

0 comments on commit abfb615

Please sign in to comment.