Unable to import models in service interface
Hi im learning Dependency Injection for the first time and making a micro-project to try it out. But I have a model class in my main project and a class from that model is needed in the service interface however im unable to import the model class in the interface.
I can import ServiceContracts in ASPNETCoreLearn2 but i can't do vice-versa even though ive properly added the project dependencies.
10 Replies
if you can import ServiceContracts in ASPNETCoreLearn2, that would imply that the ASPNETCoreLearn2 project has a dependency on ServiceContracts
as opposed to ServiceContracts having a dependency on ASPNETCoreLearn2. which contains the CityWeather type
does the .csproj for the ServiceContracts project have a reference to the ASPNETCoreLearn2 project?
project references in .NET are not bi-directional, they are one-way
i have added project dependency of each other in both the projects
wouldn't that cause a cyclical dependency?
okay so how exactly am i supposed to import the models from ASPNETCoreLearn2 and use it in the interface and then use that interface back in ASPNETCoreLearn2
ig
if you have types that are required by multiple projects, you would typically put them in a third, lower-level project
oh so i create another class library project to store the models u mean?
yep
a lot of people make a Models project for this purpose
alr that would be like 4th project in my solution
i see
ty imma try this
or they call it Core, or Base, or Impl or whatever else
unfortunately when you try to be 'clean' with projects you kinda just end up having a lot of them
it is what it is
oh
ty it worked btw