ExplicitLayers enables you to put in cross-layer dependency checks in your project.
·
Report Bug
·
Request Feature
Table of Contents
Are you tired of having discussions with your team about how to structure your project structure? Are you sick of having layers conflated with projects just to stop "bad developers" from referencing wrong things? This is exactly what you need. This nuget will add two things to your project:
- A Layer attribute for specifying to which layer a type (class, struct, interface) belongs to
- Analyzers which will warn you about forbidden references between layers
The nuget is built for .Net Standard 2.0 so it should work for both .Net Framework and .Net (Core) projects.
- Add a nuget to your project: https://www.nuget.org/packages/ExplicitLayers/
- Add configuration to your .editorconfig file
dotnet_diagnostic.ExplicitLayers.comma_separated_layer_names = Domain,Infrastructure,Web
dotnet_diagnostic.ExplicitLayers.Infrastructure.comma_separated_allowed_dependencies = Domain
dotnet_diagnostic.ExplicitLayers.Web.comma_separated_allowed_dependencies = Domain,Infrastructure
dotnet_diagnostic.ExplicitLayers.Web.comma_separated_regex_paths = .*Web.*
Add [Layer("<layer-name>")]
to your classes to specify to which layer they belong.
Add all layer names to .editorconfig config as a comma separated list dotnet_diagnostic.ExplicitLayers.comma_separated_layer_names
.
Add rules for every layer to .editorconfig as a comma separated list dotnet_diagnostic.ExplicitLayers.<layer-name>.comma_separated_allowed_dependencies
.
Optionally add rules to .editorconfig to specify all types on a certain path belonging to a certain layer as comma separated list of regex patterns dotnet_diagnostic.ExplicitLayers.<layer-name>.comma_separated_regex_paths
.
Example of warning for forbidden referencing
You're welcome to contribute if you think it needs something more.
Distributed under the GPL License. See LICENSE.txt
for more information.
TheStonehead
Project Link: https://github.com/thestonehead/ExplicitLayers