I have the following project structure with following namespaces:
ProjectName
ProjectName.Shared
ProjectName.Shared.Logging
ProjectName.DbContext
ProjectName.Shared
ProjectName.Shared.Logging
The DbContext
project is currently using a project reference to the Shared
project because we would like to log data via a solution-wide used Logger.
Now it shall be changed so that the Logger shall also write in some database. It would mean to me that it would become a circular project dependency if I try to add ProjectName.DbContext
as a project reference in ProjectName.Shared
.
It would look like this then:
ProjectName
ProjectName.Shared
ProjectName.Shared.Logging
ProjectName.DbContext
ProjectName.DbContext
ProjectName.DbContext
ProjectName.Shared
ProjectName.Shared.Logging
I was considering creating a new SubProject called ProjectName.Logging
, but I could not see how it would solve my circular dependency problem; ProjectName.Logging
would need ProjectName.DbContext
and the other way around, too.
Does someone have an idea how to solve that circular dependency?
four options:
ProjectName.Shared
and ProjectName.DbContext
assembliesProjectName.DbContext
could declare and accept an IDbLogger
interface, which is then implemented in ProjectName.Shared
and passed in, so it can do logging without having to know the detailsProjectName.Shared
and ProjectName.DbContext
would referenceILogger[<T>]
from Microsoft.Extensions.Logging.Abstractions(it is also technically possible to create a genuinely circular build, but it is horribly complicated, very brittle, and you should not consider it as anything other than a hack of absolute last resort)