Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ServiceHelper.cs
1using Waher.Events;
2
4{
5 public static class ServiceHelper
6 {
7 public static T GetService<T>()
8 where T : class
9 {
10 T? Service;
11
12 try
13 {
14 Service = MauiProgram.Current?.Services?.GetService<T>();
15 }
16 catch (Exception ex)
17 {
18#if DEBUG
19 ex = Log.UnnestException(ex);
20 App.SendAlert(ex.Message, "text/plain").Wait();
21#endif
22 throw new ArgumentException("Service not found: " + typeof(T).FullName);
23 }
24
25 if (Service is not null)
26 return Service;
27 else
28 throw new ArgumentException("Service not found: " + typeof(T).FullName);
29 }
30
31 public static object GetService(Type ServiceType)
32 {
33 object? Service = MauiProgram.Current?.Services?.GetService(ServiceType);
34
35 if (Service is not null)
36 return Service;
37 else
38 throw new ArgumentException("Service not found: " + ServiceType);
39 }
40 }
41}
The Application class, representing an instance of the Neuro-Access app.
Definition: App.xaml.cs:69
static ? MauiApp Current
Current MAUI app instance.
Definition: MauiProgram.cs:78
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
Definition: Log.cs:818