NotificationService.cs 970 B

12345678910111213141516171819202122232425262728293031
  1. using GreenTree.Nachtragsmanagement.Core.Plugins;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace GreenTree.Nachtragsmanagement.Services.Misc
  9. {
  10. public class NotificationService : INotificationService
  11. {
  12. /// <summary>
  13. /// Searches for all implementations of the INotificationPlugin
  14. /// </summary>
  15. public IEnumerable<INotificationPlugin> GetNotificationPlugins()
  16. {
  17. var type = typeof(INotificationPlugin);
  18. var assemblies = AppDomain.CurrentDomain.GetAssemblies();
  19. var types = assemblies
  20. .SelectMany(p => p.GetTypes())
  21. .Where(p => type.IsAssignableFrom(p) && !p.IsInterface)
  22. .Select(p => Activator.CreateInstance(p))
  23. .OfType<INotificationPlugin>()
  24. .ToList();
  25. return types;
  26. }
  27. }
  28. }