using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; namespace Ds.Module.DynamicApi.services { public interface IServiceFactory { T GetService(); } public class ServiceFactory : IServiceFactory { private readonly IServiceProvider _serviceProvider; public ServiceFactory(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; } public T GetService() { return _serviceProvider.GetRequiredService(); } } public abstract class ServiceBaseController : ControllerBase { protected T GetService() { return HttpContext.RequestServices.GetRequiredService(); } } }