Files
Umbraco-CMS/src/Umbraco.Web.Common/Controllers/PluginController.cs
Mole bf41c2eeaa Netcore: Align namespaces (#9801)
* Rename Umbraco.Core namespace to Umbraco.Cms.Core

* Move extension methods in core project to Umbraco.Extensions

* Move extension methods in core project to Umbraco.Extensions

* Rename Umbraco.Examine namespace to Umbraco.Cms.Examine

* Move examine extensions to Umbraco.Extensions namespace

* Reflect changed namespaces in Builder and fix unit tests

* Adjust namespace in Umbraco.ModelsBuilder.Embedded

* Adjust namespace in Umbraco.Persistence.SqlCe

* Adjust namespace in Umbraco.PublishedCache.NuCache

* Align namespaces in Umbraco.Web.BackOffice

* Align namespaces in Umbraco.Web.Common

* Ensure that SqlCeSupport is still enabled after changing the namespace

* Align namespaces in Umbraco.Web.Website

* Align namespaces in Umbraco.Web.UI.NetCore

* Align namespaces in Umbraco.Tests.Common

* Align namespaces in Umbraco.Tests.UnitTests

* Align namespaces in Umbraco.Tests.Integration

* Fix errors caused by changed namespaces

* Fix integration tests

* Undo the Umbraco.Examine.Lucene namespace change

This breaks integration tests on linux, since the namespace wont exists there because it's only used on windows.

* Fix merge

* Fix Merge
2021-02-18 11:06:02 +01:00

96 lines
3.5 KiB
C#

using System;
using System.Collections.Concurrent;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Logging;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Core.Web.Mvc;
using Umbraco.Cms.Web.Common.Attributes;
using Umbraco.Core.Persistence;
using Umbraco.Extensions;
namespace Umbraco.Cms.Web.Common.Controllers
{
/// <summary>
/// Provides a base class for plugin controllers.
/// </summary>
public abstract class PluginController : Controller, IDiscoverable
{
private static readonly ConcurrentDictionary<Type, PluginControllerMetadata> MetadataStorage
= new ConcurrentDictionary<Type, PluginControllerMetadata>();
// for debugging purposes
internal Guid InstanceId { get; } = Guid.NewGuid();
/// <summary>
/// Gets the Umbraco context.
/// </summary>
public virtual IUmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext;
/// <summary>
/// Gets the database context accessor.
/// </summary>
public virtual IUmbracoContextAccessor UmbracoContextAccessor { get; }
/// <summary>
/// Gets the database context.
/// </summary>
public IUmbracoDatabaseFactory DatabaseFactory { get; }
/// <summary>
/// Gets or sets the services context.
/// </summary>
public ServiceContext Services { get; }
/// <summary>
/// Gets or sets the application cache.
/// </summary>
public AppCaches AppCaches { get; }
/// <summary>
/// Gets or sets the profiling logger.
/// </summary>
public IProfilingLogger ProfilingLogger { get; }
/// <summary>
/// Gets metadata for this instance.
/// </summary>
internal PluginControllerMetadata Metadata => GetMetadata(GetType());
protected PluginController(IUmbracoContextAccessor umbracoContextAccessor, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger)
{
UmbracoContextAccessor = umbracoContextAccessor;
DatabaseFactory = databaseFactory;
Services = services;
AppCaches = appCaches;
ProfilingLogger = profilingLogger;
}
/// <summary>
/// Gets metadata for a controller type.
/// </summary>
/// <param name="controllerType">The controller type.</param>
/// <returns>Metadata for the controller type.</returns>
public static PluginControllerMetadata GetMetadata(Type controllerType)
{
return MetadataStorage.GetOrAdd(controllerType, type =>
{
// plugin controller? back-office controller?
var pluginAttribute = controllerType.GetCustomAttribute<PluginControllerAttribute>(false);
var backOfficeAttribute = controllerType.GetCustomAttribute<IsBackOfficeAttribute>(true);
return new PluginControllerMetadata
{
AreaName = pluginAttribute?.AreaName,
ControllerName = ControllerExtensions.GetControllerName(controllerType),
ControllerNamespace = controllerType.Namespace,
ControllerType = controllerType,
IsBackOffice = backOfficeAttribute != null
};
});
}
}
}