Reputation: 6768
Work on Aspnet core boilerplate framework stuck on one issue, form my controller failed to call services.
Application class library contains IEmployeeService and EmployeeService, how to call them from my EmployeeController.
Service
public interface IEmployeeService
{
int CreateEmployee(CreateEmployeeDto data);
IEnumerable<EmployeeListDto> GetEmployeeList();
}
public class EmployeeService : IEmployeeService
{
}
Controller
[AbpMvcAuthorize]
public class EmployeeController : HRISControllerBase
{
private readonly IEmployeeService _employeeService;
public EmployeeController(
IEmployeeService employeeService
)
{
_employeeService = employeeService;
}
public ActionResult Index()
{
return View();
}
}
Note: Do project need to configure something in ConfigureServices on the Startup.cs file.
Upvotes: 0
Views: 556
Reputation: 1637
According to the docs
"ASP.NET Boilerplate automatically registers all Repositories, Domain Services, Application Services"
As such all you should need to do is change your IEmployeeService to inherit from IApplicationService:
public interface IEmployeeService : IApplicationService
{
int CreateEmployee(CreateEmployeeDto data);
IEnumerable<EmployeeListDto> GetEmployeeList();
}
Upvotes: 0
Reputation: 2873
You can use registered your class in Startup.cs class.here asp..net core provide inbuild DI.
Upvotes: 1
Reputation: 43098
Implement ITransientDependency
.
public class EmployeeService : IEmployeeService, ITransientDependency
{
// ...
}
From https://aspnetboilerplate.com/Pages/Documents/Dependency-Injection#helper-interfaces:
ASP.NET Boilerplate provides the ITransientDependency, the IPerWebRequestDependency and the ISingletonDependency interfaces as a shortcut.
Upvotes: 1
Reputation: 904
You need register it in the ConfigureServices
method:
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IEmployeeService, EmployeeService>();
}
Upvotes: 1