-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Investigating things for easier Aspire integration #24365
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
@@ -104,6 +109,12 @@ ILoggingBuilder InitializeLogging() | |||
} | |||
} | |||
|
|||
IDictionary<object, object> IHostApplicationBuilder.Properties => throw new NotImplementedException(); | |||
|
|||
IHostEnvironment IHostApplicationBuilder.Environment => throw new NotImplementedException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is often loaded from an environment variable or some json configuration. We could (somehow) detect this as either Debug or Release, or set something during dotnet publish
, but it is a new concept.
Gets information about the hosting environment an application is running in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is (2) that I called out in #4393. I'm not sure what to do here either. Maybe just always returning Production
? Or Development
when the app is build for Debug
and Production
otherwise?
Is the plan to make these properties work? |
Yes |
08b89e5
to
5e3d70a
Compare
1ff8979
to
e045bfe
Compare
e045bfe
to
5a46c80
Compare
@@ -29,6 +32,66 @@ public static MauiAppBuilder ConfigureDispatching(this MauiAppBuilder builder) | |||
return builder; | |||
} | |||
|
|||
public static MauiAppBuilder ConfigureEnvironmentVariables(this MauiAppBuilder builder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand why we need to do this. Why can't Microsoft.Extensions.Configuration.EnvironmentVariables
be used instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: looking into Microsoft.Extensions.Configuration.EnvironmentVariables
more I guess we maybe should be able to do all of the below with the right implementation of that as well.
If we're running on iOS or Android the environment variables on those devices/Simulators/emulators are not necessarily the ones that are on the host machine.
In the case of Android we write them to a file through the Hot Reload connection and I read them directly from there as its more stable that way. For iOS we provide them through the debugger connection which works fine.
However, it doesn't end there, I want to add some magic for not using localhost since that is also something that won't work for Android.
Having all that said, I do think we might want to look into still implementing it. I remember us having some open issues to support the settings.json files etc. so it might still be beneficial.
5a46c80
to
25f16df
Compare
b502589
to
0ed9928
Compare
… in "Release" (#9933) Context: d22f04e Context: dotnet/aspire#4684 Context: dotnet/maui#24365 Context: https://github.com/jfversluis/MauiAspire Commit d22f04e set the default value of the [`$(HttpActivityPropagationSupport)' MSBuild property][0] to false, which "removes code related to diagnostics support for System.Net.Http." This was done to reduce app size. .NET Aspire also uses System.Net.Http, and we'd like to System.Net.Http diagnostics support to be available by default in that environment; see also dotnet/aspire#4684 and dotnet/maui#24365. Update the `$(HttpActivityPropagationSupport)` MSBuild property to be false by default only in "Release" configuration builds, i.e. when `$(Optimize)`=true. [0]: https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options
…9928) Context: eb6397d Context: 200f843 Context: dotnet/runtime#89880 Context: dotnet/aspire#4684 Context: dotnet/maui#24365 Context: https://github.com/jfversluis/MauiAspire .NET 8 introduced use of System.Diagnostics.Metrics into `HttpClient`, which immediately slowed down .NET for Android app startup times (dotnet/runtime#89880). This was "fixed" by *disabling* use of Metrics within .NET for Android apps *by default* (eb6397d, 200f843). Support for Metrics could be re-enabled by setting the [`$(MetricsSupport)` MSBuild property][0]. .NET Aspire also uses System.Diagnostics.Metrics, and we'd like to allow Metrics to be available by default in that environment; see also dotnet/aspire#4684 and dotnet/maui#24365. Update the `$(MetricsSupport)` MSBuild property to be false by default only in "Release" configuration builds,, i.e. when `$(Optimize)`=true. [0]: https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options
Description of Change
Imagine a world where you would be able to use .NET Aspire to also get all kinds of useful data out of your .NET MAUI app. Imagine no more, with this code that is EXACTLY what you can do ✨
This PR is part of a cross-team effort to make it easier to integrate .NET Aspire into .NET MAUI apps. Once everything is in place you will be able to easily get your apps' tracing, logging and metrics in your .NET Aspire dashboard. Inspect HTTP requests? No problem. Searching through a visually appealing overview or your
ILogger
calls? Easy peasy. Insights into your memory usage? Consider it done.And then we didn't even talk about maybe the best feature that this brings: service discovery. When using Dev Tunnels and .NET Aspire you will be able to reach your backend services regardless of where they live! No more complicated code constructions that get in the way of a delightful getting started experience.
When this is merged, this is only the beginning of beautiful things to come. This is not the final, complete solution yet, stay tuned for that in the .NET 10 release notes. Or, if you're brave enough, have a play with this and please let us know so we can make sure that come November you will be able to enjoy the best experience possible.
This PR adds the following:
MauiAppBuilder
now implementsIHostApplicationBuilder
NotImplementedException
.Minimum requirements:
(Potential) follow up actions:
Extensions.EnvironmentVariables
to simplify codeRelated PRs: