How do I conduct the Dependency Injection in Integration Test?
Calling the departmentRepository
or departmentAppService
, is giving me null
and error below.
public class DepartmentAppServiceTest
{
public SharedServicesContext context;
public IMapper mapper;
public IRepository<Department, int> departmentRepository;
public IDepartmentAppService departmentAppService;
public DepartmentAppServiceTest()
{
ServiceCollection services = new ServiceCollection();
services.AddTransient<IRepository<Department>, BaseRepository<Department>>();
services.AddTransient<IDepartmentAppService, DepartmentAppService>();
debugging and setting breakpoints, both calling this repository or app service are null,
new method
[Fact]
var departmentDto = await departmentAppService.GetDepartmentById(2);
Constructors for App Service
DepartmentAppService(departmentRepository, mapper)
DepartmentRepository(dbcontext)
Error:
Message: System.NullReferenceException : Object reference not set to an instance of an object.