How does one implement property and method dependency injection? How do I add the services? And finally, how good of an impact can that have compared to using constructor injection?
Is it possible to use property/method injection instead of constructor injection?
.Net beginner here and all the help would be appreciated <3
In my wrapper class where I am using constructor DI:
private ICustomerRepository _customerRepository; //For customer
private ICountryRepository _countryRepository; //For country
private IRegionRepository _regionRepository; //for region
private ICityRepository _cityRepository; //for city
// Constructor
public RepositoryWrapper(OmniConnectDB context, ICustomerRepository customerRepository, IMapper mapper, ICountryRepository countryRepository, IRegionRepository regionRepository, ICityRepository cityRepository)
{
_context = context;
_mapper = mapper;
_customerRepository = customerRepository;
_countryRepository = countryRepository;
_regionRepository = regionRepository;
_cityRepository = cityRepository;
}
In services:
// configure DI for Location Repositories
services.AddScoped<ICountryRepository, CountryRepository>();
services.AddScoped<IRegionRepository, RegionRepository>();
services.AddScoped<ICityRepository, CityRepository>();
// Configure DI for Customer Service
services.AddScoped<ICustomerService, CustomerService>();