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

Circular Dependency Issue when managing a whitelist of dependencies #255

Open
BrunoBeraud opened this issue Apr 19, 2024 · 0 comments
Open
Labels
kind/support Categorizes issue or PR as a support question.

Comments

@BrunoBeraud
Copy link

Hello,

Here's a test to check that my usecase class has only authorized dependencies

private readonly IObjectProvider<Interface> UseCaseInterfaces = Classes().That().HaveNameEndingWith("UseCase");

[Fact]
public void UseCasesNotHaveAnyDependenciesExceptCore()
{
    string[] whitelistDependenciesRegex = ["^System", ".*\\.Core\\..*"];
    Classes().That().Are(UseCaseClasses)
        .Should().NotDependOnAnyTypesThat().DoNotResideInNamespace(
            pattern: string.Join("|", whitelistDependenciesRegex),
            useRegularExpressions: true)
            .Because("UseCases must contains only application business concern and must not be impacted by any infrastructure concern")
            .Check(Architecture);
}

// Class to check
internal class GetAllUseCase(IRepository Repository) : IGetAllUseCase
{
    private IRepository _repository;

    public async Task<Result<IEnumerable<Entity>>> GetAllAsync()
    {
        var resultat = await __repository.GetAllAsync();
        return Result<IEnumerable<Entity>>.Success(resultat);
    }
}

In this example, the Core and System namespaces are the only authorized dependencies.
Core contains the IRepository interface.
The problem is that the "_repository" member of the usecase class is considered a dependency, which will cause the test to fail because "GetAllUseCase" depends on "GetAllUseCase"...
I can't whitelist the GetAllUseCase class because I have several use cases and this test needs to cover them all but I don't want to allow them to depend on this one (in fact more generally I don't want any of them to depend on any of the others).

How do I do this?

Thank !

@mak638 mak638 added the kind/support Categorizes issue or PR as a support question. label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question.
Projects
None yet
Development

No branches or pull requests

2 participants