I am a bit new to DI pattern and having some problems in hand. The whole story goes like this:
- There is a console app called 'DataGenerator' responsible to generate sample data for the entire app. A reference to 'Autofac' has been added to this project. Here is the code snippet for creating a list of country:
The exception raising up in the above foreach loop says:
{"None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'TechnicalTest.Service.AppServices.CountryService' can be invoked with the available services and parameters:\r\nCannot resolve parameter 'TechnicalTest.Repository.EntityRepositories.ICountryRepository countryRepository' of constructor 'Void .ctor(TechnicalTest.Repository.EntityRepositories.ICountryRepository, TechnicalTest.Repository.UnitOfWork.IUnitOfWork)'."}
- There is another project including the app services. Here is one of which:
Please note that a GenericRepository and UnitOfWork project has been added to introduce every entity repository. For example:

I have search through the web for the exception and how I could get ride of it but unfortunately could not figure out a solution for my case. I guess there must be something wrong with the CountryService constructor or something like that. Any helps or ideas would be kindly appreciated.


DbContextwith your container? From the error message it looks like the problem is with resolving the dependencies forCountryRepositorythat is the problem. - Jack Hughesbuilder.RegisterType<CountryService>().As<ICountryService>();. Isn't it enough to use the service orDbContextshould be registered too? - AliCountryRepositorywithout all of the dependencies it requires? - Jack HughesDbContextI've made a reference to myModelproject in whichDbContextandDbSet<T>have been written. Do you think this referencing would be fine in terms of design and architecture? I guess it sounds not bad as I don't know any other course of action.. - Ali