Skip to content

Instantly share code, notes, and snippets.

@nathanwoulfe
Created June 7, 2018 03:13
Show Gist options
  • Save nathanwoulfe/9861242a1dbdd1ba45b2157ff303db5d to your computer and use it in GitHub Desktop.
Save nathanwoulfe/9861242a1dbdd1ba45b2157ff303db5d to your computer and use it in GitHub Desktop.
Events from an interface
// 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