updates nuspec, creates new UmbracoApiControllerBase which is not auto-routed but contains the base services
This commit is contained in:
@@ -894,6 +894,7 @@
|
||||
<Compile Include="WebApi\MvcVersionCheck.cs" />
|
||||
<Compile Include="WebApi\NamespaceHttpControllerSelector.cs" />
|
||||
<Compile Include="WebApi\UmbracoApiController.cs" />
|
||||
<Compile Include="WebApi\UmbracoApiControllerBase.cs" />
|
||||
<Compile Include="WebApi\UmbracoApiControllerResolver.cs" />
|
||||
<Compile Include="Mvc\UmbracoAuthorizeAttribute.cs" />
|
||||
<Compile Include="Mvc\NotChildAction.cs" />
|
||||
|
||||
@@ -1,127 +1,24 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using Microsoft.Owin;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Validation;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Web.WebApi
|
||||
{
|
||||
public abstract class UmbracoApiController : ApiController
|
||||
/// <summary>
|
||||
/// The base class for auto-routed API controllers for Umbraco
|
||||
/// </summary>
|
||||
public abstract class UmbracoApiController : UmbracoApiControllerBase
|
||||
{
|
||||
protected UmbracoApiController()
|
||||
: this(UmbracoContext.Current)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected UmbracoApiController(UmbracoContext umbracoContext)
|
||||
protected UmbracoApiController(UmbracoContext umbracoContext) : base(umbracoContext)
|
||||
{
|
||||
if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
|
||||
UmbracoContext = umbracoContext;
|
||||
InstanceId = Guid.NewGuid();
|
||||
Umbraco = new UmbracoHelper(umbracoContext);
|
||||
_membershipHelper = new MembershipHelper(UmbracoContext);
|
||||
}
|
||||
|
||||
private readonly MembershipHelper _membershipHelper;
|
||||
|
||||
/// <summary>
|
||||
/// Tries to retrieve the current HttpContext if one exists.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected Attempt<HttpContextBase> TryGetHttpContext()
|
||||
{
|
||||
return Request.TryGetHttpContext();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to retrieve the current HttpContext if one exists.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected Attempt<IOwinContext> TryGetOwinContext()
|
||||
{
|
||||
return Request.TryGetOwinContext();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an ILogger
|
||||
/// </summary>
|
||||
public ILogger Logger
|
||||
{
|
||||
get { return ProfilingLogger.Logger; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a ProfilingLogger
|
||||
/// </summary>
|
||||
public ProfilingLogger ProfilingLogger
|
||||
{
|
||||
get { return UmbracoContext.Application.ProfilingLogger; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current ApplicationContext
|
||||
/// </summary>
|
||||
public ApplicationContext ApplicationContext
|
||||
{
|
||||
get { return UmbracoContext.Application; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a ServiceContext
|
||||
/// </summary>
|
||||
public ServiceContext Services
|
||||
{
|
||||
get { return ApplicationContext.Services; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a DatabaseContext
|
||||
/// </summary>
|
||||
public DatabaseContext DatabaseContext
|
||||
{
|
||||
get { return ApplicationContext.DatabaseContext; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an UmbracoHelper object
|
||||
/// </summary>
|
||||
public UmbracoHelper Umbraco { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current UmbracoContext
|
||||
/// </summary>
|
||||
public UmbracoContext UmbracoContext { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the WebSecurity instance
|
||||
/// </summary>
|
||||
public WebSecurity Security
|
||||
{
|
||||
get { return UmbracoContext.Security; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the MemberHelper instance
|
||||
/// </summary>
|
||||
public MembershipHelper Members
|
||||
{
|
||||
get { return _membershipHelper; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Useful for debugging
|
||||
/// </summary>
|
||||
internal Guid InstanceId { get; private set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
123
src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs
Normal file
123
src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using Microsoft.Owin;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Web.WebApi
|
||||
{
|
||||
/// <summary>
|
||||
/// The base class for API controllers that expose Umbraco services - THESE ARE NOT AUTO ROUTED
|
||||
/// </summary>
|
||||
public abstract class UmbracoApiControllerBase : ApiController
|
||||
{
|
||||
protected UmbracoApiControllerBase()
|
||||
: this(UmbracoContext.Current)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected UmbracoApiControllerBase(UmbracoContext umbracoContext)
|
||||
{
|
||||
if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
|
||||
UmbracoContext = umbracoContext;
|
||||
InstanceId = Guid.NewGuid();
|
||||
Umbraco = new UmbracoHelper(umbracoContext);
|
||||
_membershipHelper = new MembershipHelper(UmbracoContext);
|
||||
}
|
||||
|
||||
private readonly MembershipHelper _membershipHelper;
|
||||
|
||||
/// <summary>
|
||||
/// Tries to retrieve the current HttpContext if one exists.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected Attempt<HttpContextBase> TryGetHttpContext()
|
||||
{
|
||||
return Request.TryGetHttpContext();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to retrieve the current HttpContext if one exists.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected Attempt<IOwinContext> TryGetOwinContext()
|
||||
{
|
||||
return Request.TryGetOwinContext();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an ILogger
|
||||
/// </summary>
|
||||
public ILogger Logger
|
||||
{
|
||||
get { return ProfilingLogger.Logger; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a ProfilingLogger
|
||||
/// </summary>
|
||||
public ProfilingLogger ProfilingLogger
|
||||
{
|
||||
get { return UmbracoContext.Application.ProfilingLogger; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current ApplicationContext
|
||||
/// </summary>
|
||||
public ApplicationContext ApplicationContext
|
||||
{
|
||||
get { return UmbracoContext.Application; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a ServiceContext
|
||||
/// </summary>
|
||||
public ServiceContext Services
|
||||
{
|
||||
get { return ApplicationContext.Services; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a DatabaseContext
|
||||
/// </summary>
|
||||
public DatabaseContext DatabaseContext
|
||||
{
|
||||
get { return ApplicationContext.DatabaseContext; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an UmbracoHelper object
|
||||
/// </summary>
|
||||
public UmbracoHelper Umbraco { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current UmbracoContext
|
||||
/// </summary>
|
||||
public UmbracoContext UmbracoContext { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the WebSecurity instance
|
||||
/// </summary>
|
||||
public WebSecurity Security
|
||||
{
|
||||
get { return UmbracoContext.Security; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the MemberHelper instance
|
||||
/// </summary>
|
||||
public MembershipHelper Members
|
||||
{
|
||||
get { return _membershipHelper; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Useful for debugging
|
||||
/// </summary>
|
||||
internal Guid InstanceId { get; private set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user