I would like to receive a warning about cyclic dependency on namespace

I can arrange my code in assemblies to ensure the correct namespace dependency:

Company.Product.Domain assembly Company.Product.DataAccessLayer assembly -References Company.Product.Domain Company.Product.Application assembly -References Company.Product.Domain -References Company.Product.DataAccessLayer 

Since the link to the circular assembly is not possible, I can be sure that I am not referring to the DAL from within the domain, for example.

But this leads to a large number of assemblies, when you have several domains, I would just use namespaces to organize the project as follows:

 Company.Product assembly -Company.Product.Domain namespace -Company.Product.DataAccessLayer namespace -Company.Product.Application namespace 

Is there any way to prevent or warn about namespace dependencies that I don't want.

I have a resharper if there is a "Code Check -> Custom Template" that someone knows about.

+4
source share
1 answer

I had the same problem and I did not find the right tool that I created myself. Using (guess what): Roslyn.

It is open source and it is here: http://nsdepcop.codeplex.com

It works as follows:

  • You must define the allowed namespace dependencies in the XML files (one file for each project).
  • The tool is integrated into the MSBuild process, so it runs every time it is created and gives warnings / errors for each segment of the source code that violates the dependency rules.
  • If you set up a preview of the Roslyn end user (for VS2013), it also integrates into Visual Studio and gives feedback when you enter the code (there is no need to build to get problems).
+3
source

Source: https://habr.com/ru/post/1484644/


All Articles