- Notifications
You must be signed in to change notification settings - Fork 25.1k
Testing on different environments #9060
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
Conversation
| Can you provide an internal review topic? It's really challenging to review these changes in isolation |
| @guardrex After looking at the changes I don't think this is encouraging the right pattern. It's easier to just do TryAddXXX on startup and setup the services the normal way than rely on configure test services. Configure test services is there for use in scenarios where the pattern mentioned above can't be used, such as when configuring options for testing. (And even then, you can now use IPostConfigureOptions to get around that in most cases). The pattern mentioned above (calling plain ConfigureServices and using services.TryAdd in your startup code is the recommended approach to follow when you want to register services that you might need to override for testing). |
| @javiercn It was the first thing that came to mind: The app loads whatever services and pipeline config it requires for whatever environment it finds itself in depending on its environment (dev, staging, test, prod) ... in the normal way ... in the way that we clearly document in the App startup and Multiple environments topics, then the dev sets the environment for testing using the env var or by setting it in code in the test project the way that I show. That's super-easy to understand and comports well with what we currently document about running apps in various environments.
Even now just reading that, it's not super clear to me, so I'll think it over this weekend. |
| @guardrex Also for environment specific setups you can do Configure<>Services in your startup and setup the environment in the WebHostBuilder. Those two approaches are better than relying on ConfigureTestServices |
| WRT WRT controlling the environment for tests, are you just saying to strip out the piece that explains how to set it explicitly in |
| @javiercn How about this (on the last commit) ...
|
Why would you do this instead of just calling webhostbuilder.UseEnvironment? |
Wouldn't calling Suppose that I configure the app based on its environment in Alternatively, I could have set the environment for the app based on what I showed in the first commit ... |
Fixes #8917
cc: @seshenoy