Hi.
A problem I am having is with .NetCore WebAPI type project. Earlier running fine, throwing exception after adding swagger packages and resp. modifying the startup.cs class. Coreswagger.API is my project name.
Exception -->
Unable to resolve service for type 'CoreSwagger.API.Services.CarDataService' while attempting to activate
'CoreSwagger.API.Controllers.CarController'.
CarDataService.cs class -->
public class CarDataService:IDisposable { public List<CarModel> GetCarsByMaker(string brandname) { try { CarDataMock objCM = new CarDataMock(); return objCM.cars.Where(c => c.Brand == brandname).ToList(); } catch(Exception exp) { throw exp; } } public void Dispose() { throw new NotImplementedException(); } }
CarController.cs class -->
[Route("api/[controller]")] public class CarController : Controller { protected CarDataService cService { get; set; } public CarController(CarDataService cserv) { cService = cserv; } /// <summary> /// Get Cars by maker /// </summary> [Route("GetCarsByMaker/term")] [HttpGet] public JsonResult GetCarsByMaker(string makername) { try { var carList = cService.GetCarsByMaker(makername); return Json(carList); } catch(Exception exp) { throw exp.InnerException; } } }
Simple straightforward that ran Ok before I added swagger related stuff. Now that above exception shows up. It talks about problems with Dependency Injection(??).
But if that be so, it shouldn't have worked before adding swagger.
Where's the glitch. What extra to be added to Startup.cs class.