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

Endpoints.Filter does not work #688

Closed
peorth80 opened this issue May 17, 2024 · 1 comment
Closed

Endpoints.Filter does not work #688

peorth80 opened this issue May 17, 2024 · 1 comment
Labels
gone cold issue was closed due to loss of interest question Further information is requested

Comments

@peorth80
Copy link

Hello! I've been using Fastendpoints for some personal project, and I love it! But I think I found a bug with .UseFastendpoints and DI. Here's the current setup

  • API 1: API.Admin
    -- This API has services A, B and C registered. The API works as expected and does the work perfectly.

  • API 2: API
    -- This API has services D and E registered. The API works as expected and does the job perfectly.

  • Integration Test project
    -- Two fixtures: public class PublicFixture : AppFixture<API.Startup> and public class AdminFixture : AppFixture<API.Admin.Startup>

The Configure method on API 1 looks like this:

        builder.UseFastEndpoints(c =>
        {
            c.Endpoints.Filter = ep => ep.EndpointType.Namespace.StartsWith("API.Admin");
        });

The Configure method on API 2 looks like this:

        builder.UseFastEndpoints(c =>
        {            
            c.Endpoints.Filter = ep => !ep.EndpointType.Namespace.StartsWith("API.Admin");
        });

In short, each Configure has that filter that should only register the endpoints for that particular assembly. However, even when we get the expected true/false from the ep.EndpointType.Namespace.StartsWith("API.Admin"); call, I get a DI error that Service A is not registed in API 2. It will never be registered because API 2 does not use or need Service A

I believe having the filter should not register the dependencies in DI.

I can build a small ZIP sample with the example, if needed.

Thanks!

@dj-nitehawk
Copy link
Member

dj-nitehawk commented May 18, 2024

are you spinning up 2 different web apps (WebApplications) inside the same .net application domain?
if that's the case, there might be some potential for trouble with integration testing as you're experiencing, as FE was not designed to be used that way. however, you might be able to work around that by doing keyed service registrations.

may i know why you're putting everything in a single assembly and booting up multiple web applications in the same process? ideally, you'd be building a separate binary/assembly per each API and using something like aspire/docker compose/rider or vs "multi project running" for standing up each app in their own isolated app domains/memory space.

if i've misunderstood your use case, please attach a debuggable repro project so i can get a better understanding of what's happenning.

cheers!

@dj-nitehawk dj-nitehawk added question Further information is requested gone cold issue was closed due to loss of interest labels May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gone cold issue was closed due to loss of interest question Further information is requested
Development

No branches or pull requests

2 participants