Refactored my MVC application using entity framework as ORM and Autofac as DiContainter.
I run into the next "problem. I have a controller where i do crud operations for a object that has lots of complex properties.
here I show a simplified example that has nothing to do with project.
public class Car { public int Id {get;set;} public int Doors { get; set; } public double Miles { get; set; } ..... public Brand Brand { get; set; } public Engine Engine { get; set; } public FuelType FuelType {get;set;} } public class Brand { public int Id { get; set; } public string Name { get; set; } ..... }// Same for Engine, FuelType,.... for all these Objects I have services for CRUD actions
for objects with no complex properties i inject 1 service into my controller like
public class BrandController : Controller { readonly IBrandService brandService; public KwaliteitController(IBrandService _BrandService) { brandService = _BrandService; } //here comes actionresults for CRUD operations and etcetera... } This works fine and looks clean for my. Now the problem is for my CarController I also need all the names "or other properties" for Fueltype, Brand, Engine,....
I can retrieve these values and Id's from there service but than i have to inject them all into my controller like
public class CarController : Controller { readonly ICarService carService; readonly IBrandService brandService; readonly IFuelTypeService fuelTypeService; readonly IEngineService engineService; public KwaliteitController(ICarService _CarService IBrandService _BrandService,.....) { carService = _CarService; brandService = _BrandService; .... } } In reality I have objects with more than 10 property's like this so i wouldt have to implement more than X services into my controller. That looks to me like a serious overkill. is there a way I can accomplish this without having to use all my services for 1 controller.