You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
814 B
C#
35 lines
814 B
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Ds.Module.DynamicApi.services
|
|
{
|
|
public interface IServiceFactory
|
|
{
|
|
T GetService<T>();
|
|
}
|
|
|
|
public class ServiceFactory : IServiceFactory
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
public ServiceFactory(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
}
|
|
|
|
public T GetService<T>()
|
|
{
|
|
return _serviceProvider.GetRequiredService<T>();
|
|
}
|
|
}
|
|
|
|
public abstract class ServiceBaseController : ControllerBase
|
|
{
|
|
protected T GetService<T>()
|
|
{
|
|
return HttpContext.RequestServices.GetRequiredService<T>();
|
|
}
|
|
}
|
|
}
|