I have a C# web api project whose architecture is shown in the following Diagram (ProjectA)
In the above diagram Controllers in Project A use the services of Project A in order to do the actual job and the Services use the Repository in order to read and write on the Database. All of them use Autofac Dependency Injection. examples: Constructor of Controller that uses various services
public DKMenuController(ITokenService tokenService, IUserService userservice, IDKMenuService dkMenuService)
{
_tokenService = tokenService;
_dkMenuService = dkMenuService;
_userservice = userservice;
}
Constructor of a Service that uses the underlying repository for communication with the DB
public DKMenuService(IRepository repository)
{
this._repository = repository;
}
The various services are registered when the Application starts as follows
this.RegisterType<Repository>().As<IRepository>().InstancePerRequest();
this.RegisterType<DKMenuService>().As<IDKMenuService>().InstancePerRequest();
Now I want to add another Project (named in the example ProjectB) that is simply a Class library and will be called from a ProjectA Service, will do something and then will use ProjectA's repository pattern and save data in DB. The problem is that this design leads to circular references and the 2 projects won't compile. There exists a similar question here How to solve circular reference? but the answer is not so clear whether it's correct. Any ideas?