Created
June 7, 2018 03:13
-
-
Save nathanwoulfe/9861242a1dbdd1ba45b2157ff303db5d to your computer and use it in GitHub Desktop.
Events from an interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// interface | |
public interface IService | |
{ | |
// other stuff, but nothing related to events | |
} | |
// inheriting class | |
public class Service : IService | |
{ | |
public static event EventHandler<MyEventArgs> SomethingHappened; | |
public void SomeMethod() { | |
SomethingHappened?.Invoke(this, new MyEventArgs()); | |
} | |
} | |
// app start | |
public class RegisterEvents : ApplicationEventHandler | |
{ | |
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) | |
{ | |
Service.SomethingHappened += Service_SomethingHappened; | |
} | |
private void Service_SomethingHappened(object sender, MyEventArgs e) | |
{ | |
// do stufff | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment