Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with dependency verification #127

Open
freynetraul opened this issue Sep 29, 2023 · 3 comments
Open

Help with dependency verification #127

freynetraul opened this issue Sep 29, 2023 · 3 comments

Comments

@freynetraul
Copy link

Hello, I have been trying to get the library to check the following:

example: I have the layers

Application,
Core,
Infrastructure

I need the application layer to depend solely and exclusively on Core, I have tried all of this:

var result2 = Types.InCurrentDomain().That().ResideInNamespace("Application")
.Should().OnlyHaveDependenciesOn("Core").GetResult();

var result3 = Types.InCurrentDomain().That().ResideInNamespace("Application")
.Should().HaveDependencyOnAny("Core").GetResult();

var result5 = Types.InCurrentDomain().That().AreClasses().And().ResideInNamespace("Application")
.ShouldNot().HaveDependenciesOtherThan("Core").GetResult();

but it doesn't work, because in the first case it will throw an error because there are types that do not depend exclusively on Core in Application, in the second and third also it will throw an error, because there are types that do not depend on Core and that's fine, it's really what I want, verify that Application depends solely and exclusively on Core, ignoring those types that do not depend on anything.

@NeVeSpl
Copy link
Contributor

NeVeSpl commented Sep 29, 2023

Just do not forget about adding .net "System" namespace, and try this:

var result2 = Types.InCurrentDomain().That().ResideInNamespace("Application")
.Should().OnlyHaveDependenciesOn("Core", "System").GetResult();

or

var result5 = Types.InCurrentDomain().That().AreClasses().And().ResideInNamespace("Application")
.ShouldNot().HaveDependenciesOtherThan("Core", "System").GetResult();

@freynetraul13
Copy link

Just do not forget about adding .net "System" namespace, and try this:

var result2 = Types.InCurrentDomain().That().ResideInNamespace("Application")
.Should().OnlyHaveDependenciesOn("Core", "System").GetResult();

or

var result5 = Types.InCurrentDomain().That().AreClasses().And().ResideInNamespace("Application")
.ShouldNot().HaveDependenciesOtherThan("Core", "System").GetResult();

Ok, let's say I map all those dependencies explicitly on which I exclusively want to depend, what about all the new nugets that come out in the development process, would I have to be editing this line of code every time?

@NeVeSpl
Copy link
Contributor

NeVeSpl commented Sep 29, 2023

There is no magic, how the library is supposed to know which dependency is good and which one is bad? You have two options:

  • define a list of namespaces that are allowed or
  • define a list of namespaces that are forbidden

Usually, the one that is shorter and more stable is a better choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants