Interface IUmbracoContextFactory
Creates and manages UmbracoContext instances.
Namespace: Umbraco.Web
Assembly: Umbraco.Web.dll
Syntax
public interface IUmbracoContextFactory
Methods
View SourceEnsureUmbracoContext(HttpContextBase)
Ensures that a current UmbracoContext exists.
Declaration
UmbracoContextReference EnsureUmbracoContext(HttpContextBase httpContext = null)
Parameters
Type | Name | Description |
---|---|---|
System.Web.HttpContextBase | httpContext | An optional http context. |
Returns
Type | Description |
---|---|
UmbracoContextReference |
Remarks
If an UmbracoContext is already registered in the IUmbracoContextAccessor, returns a non-root reference to it. Otherwise, create a new instance, registers it, and return a root reference to it.
If httpContext
is null, the factory tries to use
System.Web.HttpContext.Current if it exists. Otherwise, it uses a dummy
System.Web.HttpContextBase.
Examples
using (var contextReference = contextFactory.EnsureUmbracoContext()) { var umbracoContext = contextReference.UmbracoContext; // use umbracoContext... }