Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
In umbraco v7 we make use of ApplicationContext which throws an error when upgrading to v8 , and also when we make us of IScope we get an error on getting the cache.
public abstract class ApiServiceBase { protected readonly Uri baseUrl; protected readonly ApplicationContext appContext; protected readonly UmbracoContext umbContext; protected readonly IRuntimeCacheProvider cache; protected readonly IPublishedContent tradeRoot; protected readonly IPublishedContent publicRoot; public ApiServiceBase(ApplicationContext appContext, UmbracoContext umbContext) { ApplicationContext applicationContext = appContext; if (applicationContext == null) throw new ArgumentNullException(nameof(appContext)); this.appContext = applicationContext; UmbracoContext umbracoContext = umbContext; if (umbracoContext == null) throw new ArgumentNullException(nameof(umbContext)); this.umbContext = umbracoContext; this.cache = appContext.ApplicationCache.RuntimeCache; this.baseUrl = WebAPI.Helpers.UriHelper.GetBaseUriForSite(umbContext.HttpContext); this.tradeRoot = this.cache.GetUmbracoCacheItem<IPublishedContent>("ApiCache.TradeRoot", (Func<IPublishedContent>)(() => umbContext.ContentCache.GetAtRoot().FirstOrDefault<IPublishedContent>((Func<IPublishedContent, bool>)(c => c.ContentType.Alias == "Home"))), 240); } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public EventsResponse GetAll() { LogHelper.Info<EventsController>(string.Format("Web API request to {0} via {1}", Request.RequestUri, Request?.Headers.UserAgent)); EventsResponse eventsResponse = new EventsResponse(); EventsService eventsService = new EventsService(this.ApplicationContext, this.UmbracoContext); try { eventsResponse.events = eventsService.GetAllevents(); eventsResponse.Success = true; } catch (Exception ex) { LogHelper.Info<EventsController>(string.Format("API Error calling events GetAll - {0}", ex.ToString())); eventsResponse.Error = ex.Message; } return eventsResponse; }
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
ApplicationContext throw error on API services after upgrade to v8
In umbraco v7 we make use of ApplicationContext which throws an error when upgrading to v8 , and also when we make us of IScope we get an error on getting the cache.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.