After building the HostProvider, assign the IServiceProvider to the class
GetServiceProvider._ = host.Services;Then use anywhere in the application to DPI classes
GetServiceProvider.GetServiceOrCreateInstance<SomeClass>()| public static class GetServiceProvider | |
| { | |
| public static IServiceProvider _ { get; set; } | |
| public static T GetServiceOrCreateInstance<T>() | |
| { | |
| return ActivatorUtilities.GetServiceOrCreateInstance<T>(_); | |
| } | |
| public static object GetServiceOrCreateInstance(Type type) | |
| { | |
| return ActivatorUtilities.GetServiceOrCreateInstance(_, type); | |
| } | |
| } |