-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[.NET Core 3] ApplicationModel finding only in original assembly #15373
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
Comments
@wisepotato thanks for contacting us. This is likely due to changes in hosting and the fact that you are using a derived startup class. Check the following:
If you have a standard Program.cs from .net core 3.0 having multiple startups is not going to work well.
In 3.0 the ConfigureServices callback gets queued inmediately when you call UseStartup and the result if you call UseStartup again is that it will queue another ConfigureServices callback from that second Startup class, which will result in both Startup callbacks running, which might not be what you want. |
Any way to have derived startup classes for e2e tests? I wouldn't want both startup classes to queue ConfigureServices.. |
@wisepotato I'm not sure there's any way with the way the new hosting works, other than passing a flag or similar to the CreateWebHostBuilder method and check that flag to avoid calling @davidfowl @Tratcher Thoughts? |
To rephrase my question: is my current setup with derived startups the way to go? Is this not common practice? I need different configs for different testing enviornments (disabling middleware, spoofing user authentication, different naming convention for routes etc..) |
Usecase: testing client generated ids in JsonApiDotNetCore (a framework that implements json:api spec). In the codebase we have an example project dedicated to e2e testing. Its default We can avoid the problem for now by moving |
This seems like a mixture of concerns, let's say I have feature switches 1 till 35. Your solution would require me to facilitatie this with: if(env.IsEnvironment("testing_One"){
FeatureSwitchOne();
}
if(env.IsEnvironment("testing_Two"){
FeatureSwitchOne();
}
.
.
.
if(env.IsEnvironment("testing_35"){
FeatureSwitchThirtyFive();
} I think environment switching is enough for most people, but If i want to test 1 to 35 with combinations of them, I could in theory have 35*34 = 1190 combinations i would need to clutter my So it will not do it for me :( |
Or in your dev and test environments you load the individual switches from the dev/test config. |
How would I approach that? Maybe this is me misunderstanding but I would like individual tests to be able to set switches, from the test itself. Is this not common practice? If not, then I guess i'm misunderstanding. |
Tried to use |
<Deleted by @anurse. We shouldn't be using this flow for issues in Discussions. I'll update the bot.> |
The theory was to inject IConfiguration into Startup and then have it query configuration keys to enable/disable features. Tests can provide in-memory configuration overrides to toggle individual features. |
So my startup knows about how tests are run? I mean I want to disable the middleware in my tests but I don't want that to EVER happen in production. Is this really the idea? Because that would mean all the options i want to test/disable in my tests should be checked in my startup, creating a lot of checking and passes. While I could also override it in a clean new startup. So my question is: why not both ways? I see uses for your version, but my version seems.. cleaner. Maybe I'm mistaken. |
Startup controls how your app runs in any environment. If you want to provide a different startup for tests, that's up to you. |
So thats kind of my point, my test startup has to be in the assembly i'm testing. Not in my testing assembly, where I would expect them to be. But yeah, that's atleast a start and one way to do it. |
Thank you for contacting us. Due to no activity on this issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue. |
Describe the bug
I'm having an issue with the
MapControllers
method ofUseEndpoints
.my thought process:
For the class
when injected into the apply method of an
IControllerResourceMapping
, the controllers that are located on theControllers
property are based on the assembly the derviedStartup
file is in (which callsIApplicationBuilder.UseRouting
/IApplicationBuilder.UseEndpoints
).I have a
TestStartup
(assembly B) that extendsStartup
(assembly A) which calls theIApplicationBuilder.UseRouting
/IApplicationBuilder.UseEndpoints
behaviour, whereUseEndpoints
hasMapControllers
in it.I only get controllers in assembly B, not the ones in assembly A (the ones i want). Is this expected behaviour?
This behaviour is inside of a framework, will try to get a minimum code sample asap.
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
The text was updated successfully, but these errors were encountered: