Gets inbound routing working, reduces the amount of non injected dependencies, reduces the amount of DomainHelper instances
This commit is contained in:
@@ -11,23 +11,27 @@ namespace Umbraco.Web.Models
|
||||
{
|
||||
public static class ContentExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the culture that would be selected to render a specified content,
|
||||
/// within the context of a specified current request.
|
||||
/// </summary>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="current">The request Uri.</param>
|
||||
/// <returns>The culture that would be selected to render the content.</returns>
|
||||
public static CultureInfo GetCulture(this IContent content, Uri current = null)
|
||||
{
|
||||
return GetCulture(UmbracoContext.Current,
|
||||
Current.Services.DomainService,
|
||||
Current.Services.LocalizationService,
|
||||
Current.Services.ContentService,
|
||||
content.Id, content.Path,
|
||||
current);
|
||||
}
|
||||
//TODO: Not used
|
||||
///// <summary>
|
||||
///// Gets the culture that would be selected to render a specified content,
|
||||
///// within the context of a specified current request.
|
||||
///// </summary>
|
||||
///// <param name="content">The content.</param>
|
||||
///// <param name="current">The request Uri.</param>
|
||||
///// <returns>The culture that would be selected to render the content.</returns>
|
||||
//public static CultureInfo GetCulture(this IContent content, Uri current = null)
|
||||
//{
|
||||
// return GetCulture(UmbracoContext.Current,
|
||||
// Current.Services.DomainService,
|
||||
// Current.Services.LocalizationService,
|
||||
// Current.Services.ContentService,
|
||||
// content.Id, content.Path,
|
||||
// current);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
//TODO: Not used - only in tests
|
||||
/// <summary>
|
||||
/// Gets the culture that would be selected to render a specified content,
|
||||
/// within the context of a specified current request.
|
||||
@@ -42,6 +46,7 @@ namespace Umbraco.Web.Models
|
||||
/// <returns>The culture that would be selected to render the content.</returns>
|
||||
internal static CultureInfo GetCulture(UmbracoContext umbracoContext,
|
||||
IDomainService domainService, ILocalizationService localizationService, IContentService contentService,
|
||||
ISiteDomainHelper siteDomainHelper,
|
||||
int contentId, string contentPath, Uri current)
|
||||
{
|
||||
var route = umbracoContext == null
|
||||
@@ -49,9 +54,9 @@ namespace Umbraco.Web.Models
|
||||
: umbracoContext.ContentCache.GetRouteById(contentId); // may be cached
|
||||
|
||||
var domainCache = umbracoContext == null
|
||||
? new PublishedCache.XmlPublishedCache.DomainCache(domainService) // for tests only
|
||||
? new PublishedCache.XmlPublishedCache.DomainCache(domainService, localizationService) // for tests only
|
||||
: umbracoContext.PublishedShapshot.Domains; // default
|
||||
var domainHelper = new DomainHelper(domainCache);
|
||||
var domainHelper = umbracoContext.GetDomainHelper(siteDomainHelper);
|
||||
Domain domain;
|
||||
|
||||
if (route == null)
|
||||
@@ -59,6 +64,8 @@ namespace Umbraco.Web.Models
|
||||
// if content is not published then route is null and we have to work
|
||||
// on non-published content (note: could optimize by checking routes?)
|
||||
|
||||
// fixme - even non-published content is stored in the cache or in the cmsContentNu table which would be faster to lookup
|
||||
|
||||
var content = contentService.GetById(contentId);
|
||||
if (content == null)
|
||||
return GetDefaultCulture(localizationService);
|
||||
@@ -93,7 +100,7 @@ namespace Umbraco.Web.Models
|
||||
|
||||
private static CultureInfo GetDefaultCulture(ILocalizationService localizationService)
|
||||
{
|
||||
var defaultLanguage = localizationService.GetAllLanguages().FirstOrDefault();
|
||||
var defaultLanguage = localizationService.GetDefaultVariantLanguage();
|
||||
return defaultLanguage == null ? CultureInfo.CurrentUICulture : new CultureInfo(defaultLanguage.IsoCode);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
@@ -13,7 +14,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
/// </summary>
|
||||
internal class ContentMapperProfile : Profile
|
||||
{
|
||||
public ContentMapperProfile(IUserService userService, ILocalizedTextService textService, IContentService contentService, IContentTypeService contentTypeService, IDataTypeService dataTypeService, ILocalizationService localizationService)
|
||||
public ContentMapperProfile(IUserService userService, ILocalizedTextService textService, IContentService contentService, IContentTypeService contentTypeService, IDataTypeService dataTypeService, ILocalizationService localizationService, ILogger logger)
|
||||
{
|
||||
// create, capture, cache
|
||||
var contentOwnerResolver = new OwnerResolver<IContent>(userService);
|
||||
@@ -24,7 +25,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
var contentTypeBasicResolver = new ContentTypeBasicResolver<IContent, ContentItemDisplay>();
|
||||
var contentTreeNodeUrlResolver = new ContentTreeNodeUrlResolver<IContent, ContentTreeController>();
|
||||
var defaultTemplateResolver = new DefaultTemplateResolver();
|
||||
var contentUrlResolver = new ContentUrlResolver();
|
||||
var contentUrlResolver = new ContentUrlResolver(textService, contentService, logger);
|
||||
var variantResolver = new ContentItemDisplayVariationResolver(localizationService);
|
||||
|
||||
//FROM IContent TO ContentItemDisplay
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
@@ -8,13 +10,24 @@ namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
internal class ContentUrlResolver : IValueResolver<IContent, ContentItemDisplay, string[]>
|
||||
{
|
||||
private readonly ILocalizedTextService _textService;
|
||||
private readonly IContentService _contentService;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public ContentUrlResolver(ILocalizedTextService textService, IContentService contentService, ILogger logger)
|
||||
{
|
||||
_textService = textService;
|
||||
_contentService = contentService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public string[] Resolve(IContent source, ContentItemDisplay destination, string[] destMember, ResolutionContext context)
|
||||
{
|
||||
var umbracoContext = context.GetUmbracoContext(throwIfMissing: false);
|
||||
|
||||
var urls = umbracoContext == null
|
||||
? new[] {"Cannot generate urls without a current Umbraco Context"}
|
||||
: source.GetContentUrls(umbracoContext).ToArray();
|
||||
: source.GetContentUrls(umbracoContext.UrlProvider, _textService, _contentService, _logger).ToArray();
|
||||
|
||||
return urls;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user