I used to have this class that extended ApplicationStartupHandler to wire up Document.AfterPublish += AfterPublish; this event. Now mre Resharper tells me I should use IApplicationEventHandler instead. Anyone has experience with this? This interface wants me to implement these:
public void OnApplicationInitialized(UmbracoApplication httpApplication, ApplicationContext applicationContext)
{
}
public void OnApplicationStarting(UmbracoApplication httpApplication, ApplicationContext applicationContext)
{
}
public void OnApplicationStarted(UmbracoApplication httpApplication, ApplicationContext applicationContext)
{
}
Simply register your events in OnApplicationStarting, just as you did in a ctor of a class deriving from ApplicationBase. Same code, just need to put it in a different place.
public class AppEvents : IApplicationEventHandler { public void OnApplicationInitialized(UmbracoApplication httpApplication, ApplicationContext applicationContext) {
but my problem is it runs twice? so you got 2 times the same event.. if i set up a debugger i also got two hits. Dirk don't you have this problem? Have you got a example class you you did this?
Alright Dirk, thanks! Got this working, here's a paste from an answer I gave in another post from my experience with this. I put mine in OnApplicationInitialized, tomorow I'll test for what Edwin is bringing up, I don't think I've ran through these with my debugger, I'll give it a look!
usingSystem; usingSystem.Linq; usingUmbraco.Core; usingUmbraco.Web; using umbraco.BusinessLogic; using umbraco.businesslogic; using umbraco.cms.businesslogic; using umbraco.cms.businesslogic.web;
Yes worked like I wanted still havent gotten around to cinfirm events only fire once, but I'm confident. Want to paste you code in here for us to take a look at what might be the problem?
(PS: I'll be away for 4 days, so if I don't write back it's not because I'm mean hah)
Well the difference is that you are hooking into publicvoidOnApplicationStartingand me publicvoidOnApplicationInitialized. There is probably a difference there, can you move it to publicvoidOnApplicationInitialized?
Hmm... That's quite strange, monday I can try a few things (I'm not at work), I guess this may mean that you application is starting twice? Sorry I can't help more :(
Wiring up events with IApplicationEventHandler
Hello,
I used to have this class that extended ApplicationStartupHandler to wire up Document.AfterPublish += AfterPublish; this event. Now mre Resharper tells me I should use IApplicationEventHandler instead. Anyone has experience with this? This interface wants me to implement these:
But really all I want is to register my event...
Not sure what I'm asking here :D
Thanks!
Seb
Sebastien
Simply register your events in OnApplicationStarting, just as you did in a ctor of a class deriving from ApplicationBase. Same code, just need to put it in a different place.
Cheers,
/Dirk
I got this:
public class AppEvents : IApplicationEventHandler {
public void OnApplicationInitialized(UmbracoApplication httpApplication, ApplicationContext applicationContext) {
}
public void OnApplicationStarting(UmbracoApplication httpApplication, ApplicationContext applicationContext) {
Document.AfterPublish += DocumentEvents.Document_AfterPublish;
Document.AfterSave += DocumentEvents.Document_AfterSave;
}
public void OnApplicationStarted(UmbracoApplication httpApplication, ApplicationContext applicationContext) {
}
}
but my problem is it runs twice? so you got 2 times the same event.. if i set up a debugger i also got two hits. Dirk don't you have this problem? Have you got a example class you you did this?
Alright Dirk, thanks! Got this working, here's a paste from an answer I gave in another post from my experience with this. I put mine in OnApplicationInitialized, tomorow I'll test for what Edwin is bringing up, I don't think I've ran through these with my debugger, I'll give it a look!
Thanks!
Seb
@Sebastien, does it work with your version? I still got this problem.
Hi Edwin,
Yes worked like I wanted still havent gotten around to cinfirm events only fire once, but I'm confident. Want to paste you code in here for us to take a look at what might be the problem?
(PS: I'll be away for 4 days, so if I don't write back it's not because I'm mean hah)
just look 3 post before this one, i've already posted it.
Well the difference is that you are hooking into publicvoidOnApplicationStartingand me publicvoidOnApplicationInitialized. There is probably a difference there, can you move it to publicvoidOnApplicationInitialized?
Doesn't change anything, i've tried already in all the different events but they alle start 2 times.
Hmm... That's quite strange, monday I can try a few things (I'm not at work), I guess this may mean that you application is starting twice? Sorry I can't help more :(
Is it too late to add question here? Where in the folder structure do you create that class to start with?!
Just a related question here:
I have tried both ApplicationEventHandler and IApplicationEventHandler and they are both working fine and same for me.
My question is which one is better to use ?
is working on a reply...