Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetModelContentType: throw exception when no UmbracoContext exists #224

Open
wants to merge 1 commit into
base: v8/dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/Umbraco.ModelsBuilder/Umbraco/PublishedModelUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ public static class PublishedModelUtility

public static IPublishedContentType GetModelContentType(PublishedItemType itemType, string alias)
{
var facade = Current.UmbracoContext.PublishedSnapshot; // fixme inject!
var umbracoContext = Current.UmbracoContext;
if (umbracoContext == null) throw new InvalidOperationException("This method requires an UmbracoContext, ensure this is created using IUmbracoContextFactory.EnsureUmbracoContext().");

var publishedSnapshot = umbracoContext.PublishedSnapshot;
switch (itemType)
{
case PublishedItemType.Content:
return facade.Content.GetContentType(alias);
return publishedSnapshot.Content.GetContentType(alias);
case PublishedItemType.Media:
return facade.Media.GetContentType(alias);
return publishedSnapshot.Media.GetContentType(alias);
case PublishedItemType.Member:
return facade.Members.GetContentType(alias);
return publishedSnapshot.Members.GetContentType(alias);
default:
throw new ArgumentOutOfRangeException(nameof(itemType));
}
Expand Down