Expose custom context into the applicationevenhandler
Hi all,
I have a AppContext in my App.Web project which includes a ServiceContext from my App.Core project.
My service context contains all of the services to make interactions with my custom database tables.
I have exposed this AppContext into the HttpContextBase. Something like the UmbracoContext.
Everything is working fine, I have a UmbracoAuthorizedJsonController where I can call my services and do operations. The problem is when I create my custom events in the App.Core project.
/// <summary>
/// Implement custom application events
/// </summary>
public class NotelyEvents: ApplicationEventHandler
{
// Fired when application is started
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
// .....
// Add events
ContentService.Deleted += ContentService_Deleted;
ContentService.EmptiedRecycleBin += ContentService_EmptiedRecycleBin;
}
// Event fires when clicking on Empty recycle bin
private void ContentService_EmptiedRecycleBin(IContentService sender, Umbraco.Core.Events.RecycleBinEventArgs e)
{
// Check if we are in the content recycle bin
if(e.IsContentRecycleBin)
{
// I need my ServiceContext here
}
}
// Events fires when deleting a node from the recycle bin
private void ContentService_Deleted(IContentService sender, Umbraco.Core.Events.DeleteEventArgs<Umbraco.Core.Models.IContent> e)
{
// I need my ServiceContext here
}
}
So basically I need to get my ServiceContext to do some stuff when deleting content nodes.
Expose custom context into the applicationevenhandler
Hi all,
I have a
AppContext
in myApp.Web
project which includes aServiceContext
from myApp.Core
project.My service context contains all of the services to make interactions with my custom database tables.
I have exposed this
AppContext
into theHttpContextBase
. Something like theUmbracoContext
.Everything is working fine, I have a
UmbracoAuthorizedJsonController
where I can call my services and do operations. The problem is when I create my custom events in theApp.Core
project.So basically I need to get my ServiceContext to do some stuff when deleting content nodes.
How can I do this?
/Michaël
UPDATE
Ok I got it working by just creating a new instance of the ServiceContext in each event instead of taking it from the HttpContextBase.
/Michaël
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.