protected void PopulateAgents() { var baseSearchType = typeof(BaseNotification <>).Name; var ass = typeof(NotificationService).GetTypeInfo().Assembly; foreach (var ti in ass.DefinedTypes) { if (ti?.BaseType?.Name == baseSearchType) { var type = ti?.AsType(); var ctors = type.GetConstructors(); var ctor = ctors.FirstOrDefault(); var services = new List <object>(); foreach (var param in ctor.GetParameters()) { services.Add(_provider.GetService(param.ParameterType)); } var item = Activator.CreateInstance(type, services.ToArray()); NotificationAgents.Add((INotification)item); } } }
/// <summary> /// Sends a notification to the user, this is usually for testing the settings. /// </summary> /// <param name="model">The model.</param> /// <param name="settings">The settings.</param> /// <returns></returns> public async Task Publish(NotificationOptions model, Settings.Settings.Models.Settings settings) { var notificationTasks = NotificationAgents.Select(notification => NotifyAsync(notification, model, settings)); await Task.WhenAll(notificationTasks).ConfigureAwait(false); }