无法从 aspnetboilerplate asp.net-核心项目控制器调用服务

Failed to call service from aspnetboilerplate asp.net-core project controller

致力于 Aspnet 核心样板框架 卡在一个问题上,我的控制器无法调用服务。

Application class 库包含 IEmployeeServiceEmployeeService,如何从我的 EmployeeController[ 调用它们=29=].

服务

    public interface IEmployeeService
    {
        int CreateEmployee(CreateEmployeeDto data);
        IEnumerable<EmployeeListDto> GetEmployeeList();

    }
 public class EmployeeService : IEmployeeService
    {
}

控制器

    [AbpMvcAuthorize]
    public class EmployeeController : HRISControllerBase
    {


        private readonly IEmployeeService _employeeService;

        public EmployeeController(           
            IEmployeeService employeeService
           )
        {

            _employeeService = employeeService;           
        }

        public ActionResult Index()
        {
            return View();
        }
}

注意:项目是否需要在 Startup.cs 文件的 ConfigureServices 中配置一些东西。

需要在ConfigureServices方法中注册:

public void ConfigureServices(IServiceCollection services)
{
    services.AddTransient<IEmployeeService, EmployeeService>();
}

实施ITransientDependency.

public class EmployeeService : IEmployeeService, ITransientDependency
{
    // ...
}

来自https://aspnetboilerplate.com/Pages/Documents/Dependency-Injection#helper-interfaces

ASP.NET Boilerplate provides the ITransientDependency, the IPerWebRequestDependency and the ISingletonDependency interfaces as a shortcut.

您可以在 Startup.cs class.here asp 中使用注册您的 class..net core 提供内置 DI。

根据 docs

"ASP.NET Boilerplate automatically registers all Repositories, Domain Services, Application Services"

因此,您需要做的就是将 IEmployeeService 更改为继承自 IApplicationService:

public interface IEmployeeService : IApplicationService
{
    int CreateEmployee(CreateEmployeeDto data);
    IEnumerable<EmployeeListDto> GetEmployeeList();
}