using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using System; namespace ReZero.SuperAPI { /// /// The main class of the application, used for managing dependency injection and service location. /// public class ApplicationServiceProvider { private readonly IApplicationBuilder _app; /// /// Constructor that accepts an instance. /// /// The dependency injection container. public ApplicationServiceProvider(IApplicationBuilder serviceProvider) { _app = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); } /// /// Gets an instance of the specified service type. /// /// The type of service to retrieve. /// An instance of the specified service type. public T GetService() where T : class { // Get the IOC container (service provider) var serviceProvider = _app.ApplicationServices; // Perform the operation using the IOC container var myService = serviceProvider!.GetRequiredService(); return myService; } } }