Skip to content

Remove MS.Extensions.Hosting from Maui #4505

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

Merged
merged 3 commits into from
Feb 6, 2022
Merged

Conversation

eerhardt
Copy link
Member

@eerhardt eerhardt commented Feb 4, 2022

  • Remove MS.Extensions.Hosting as a dependency. Users can configure DI servcies, Configuration, and Logging without needing the indirection by going through Hosting to build the ServiceProvider.
  • Add a new ConfigureContainer method to MauiApplicationBuilder so the DI implementation can be replaced.
  • Remove Logging Providers by default. Libraries can still get ILogger services, as normal. Apps can add the logging providers they care about.

Fix #4393
Fix #4394

cc @mattleibow @Redth @PureWeen

- Remove MS.Extensions.Hosting as a dependency. Users can configure DI servcies, Configuration, and Logging without needing the indirection by going through Hosting to build the ServiceProvider.
- Remove Logging Providers by default. Libraries can still get ILogger services, as normal. Apps can add the logging providers they care about.

Fix dotnet#4393
Fix dotnet#4394
@jonathanpeppers
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@Redth Redth requested review from mattleibow and PureWeen February 4, 2022 14:52
@PureWeen PureWeen requested a review from rmarinho February 4, 2022 16:50
Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

While poking around I noticed that our two CreateBuilder methods seem kind of redundant

public static MauiAppBuilder CreateBuilder() => new();
/// <summary>
/// Initializes a new instance of the <see cref="MauiAppBuilder"/> class with optional defaults.
/// </summary>
/// <param name="useDefaults">Whether to create the <see cref="MauiAppBuilder"/> with common defaults.</param>
/// <returns>The <see cref="MauiAppBuilder"/>.</returns>
public static MauiAppBuilder CreateBuilder(bool useDefaults = true) => new(useDefaults);

Feels like we should just delete the first one since the second one takes an optional parameter. Not sure if there's an advantage to having both.

I realize you didn't touch those but maybe while we're here :-)

@Eilon Eilon added the area-core-hosting Extensions / Hosting / AppBuilder / Startup label Feb 4, 2022
@eerhardt
Copy link
Member Author

eerhardt commented Feb 4, 2022

While poking around I noticed that our two CreateBuilder methods seem kind of redundant

On it.

@jsuarezruiz
Copy link
Contributor

Do we have metrics about how it impacts in the startup time?

@pictos
Copy link
Contributor

pictos commented Feb 4, 2022

@jsuarezruiz you can find the numbers here

- remove redundant and unusable methods on MauiApp
@eerhardt
Copy link
Member Author

eerhardt commented Feb 5, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@jamesmontemagno
Copy link
Member

A few questions here:
1.) Is functionality removed at all? For example the new Constructor Injection for Shell?
2.) Does this have any impact with sharing code with Blazor? (I think you answered this)
3.) We expose any of these in the implicit usings
4.) Any impact on templates?

@eerhardt
Copy link
Member Author

eerhardt commented Feb 5, 2022

@jamesmontemagno -

1.) As far as I know, no functionality that anyone is using. The pieces that are getting removed are all related to "startup" of the app. Instead of trying to interoperate with the "Generic Host" to build the DI container, we are now doing it ourselves. And we are no longer adding logging providers by default. There shouldn't be any DI functionality removed at all - like the new Constructor Injection for Shell.

2.) It doesn't impact control / component sharing with Blazor at all. The only impact it could have is if someone has extension methods that only take an IHostBuilder, since we will no longer have an IHostBuilder. In those cases, the same extension methods couldn't be used with Blazor WASM, since they also don't have an IHostBuilder either.

3.) I don't think so. I searched for "Extensions.Hosting" in the whole repo, and only this Sample.Server.WebAuthenticator is left after these changes.

4.) The one potential impact on the templates we could consider is conditionally adding a Debug log provider when the app is built for Debug. Today we are shipping the "Debug" log provider even in a Release built app. But that log provider doesn't do anything unless a debugger is attached.

@jamesmontemagno
Copy link
Member

@eerhardt LOVELY! Thank you so much for the detailed response, detailed PR, detailed issue! 👏👏👏👏👏

@Redth Redth merged commit d27a522 into dotnet:main Feb 6, 2022
eerhardt added a commit to eerhardt/maui that referenced this pull request Feb 7, 2022
* Remove MS.Extensions.Hosting from Maui

- Remove MS.Extensions.Hosting as a dependency. Users can configure DI servcies, Configuration, and Logging without needing the indirection by going through Hosting to build the ServiceProvider.
- Remove Logging Providers by default. Libraries can still get ILogger services, as normal. Apps can add the logging providers they care about.

Fix dotnet#4393
Fix dotnet#4394

* PR feedback

- remove redundant and unusable methods on MauiApp

Co-authored-by: redth <jondick@gmail.com>
@eerhardt eerhardt deleted the RemoveHosting branch February 7, 2022 16:26
Redth added a commit that referenced this pull request Feb 8, 2022
* Remove MS.Extensions.Hosting from Maui

- Remove MS.Extensions.Hosting as a dependency. Users can configure DI servcies, Configuration, and Logging without needing the indirection by going through Hosting to build the ServiceProvider.
- Remove Logging Providers by default. Libraries can still get ILogger services, as normal. Apps can add the logging providers they care about.

Fix #4393
Fix #4394

* PR feedback

- remove redundant and unusable methods on MauiApp

Co-authored-by: redth <jondick@gmail.com>

Co-authored-by: redth <jondick@gmail.com>
@Syed-RI
Copy link

Syed-RI commented Jul 15, 2022

So how does one go about adding logging now? i.e. Microsoft.Extensions.Logging.Debug or serilog to use via DI and MAUI?

@Eilon
Copy link
Contributor

Eilon commented Jul 15, 2022

@Syed-RI the upcoming update to .NET MAUI will have this by default: https://github.com/dotnet/maui/pull/8180/files

But for now, add a NuGet reference to Microsoft.Extensions.Logging.Debug, and then in MauiProgram.cs add code like this:

using Microsoft.Extensions.Logging;

...

#if DEBUG
		builder.Logging.AddDebug();
#endif

@Syed-RI
Copy link

Syed-RI commented Jul 15, 2022

That doesn't output anything I'm afraid (ILogger.LogDebug). Do you want me to create and attach a repro?

@Syed-RI
Copy link

Syed-RI commented Jul 15, 2022

However, ILogger.LogInformation does provide output on the console. Seems the log level is set somewhere but I dont know where and cant find any documentation on it either. Any pointers?

@Eilon
Copy link
Contributor

Eilon commented Jul 15, 2022

@Syed-RI if something isn't working, please log a new issue so that we can investigate. It sounds like in your case some messages are indeed being filtered if some log levels are showing up and some aren't. Lots more info here to get you started: https://docs.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line (though note that some features like setting filters in appsettings.json don't work by default in .NET MAUI).

@Syed-RI
Copy link

Syed-RI commented Jul 18, 2022

@Eilon per your suggestion #8818

@github-actions github-actions bot locked and limited conversation to collaborators Dec 21, 2023
@samhouts samhouts added the fixed-in-6.0.200-preview.14.2 Look for this fix in 6.0.200-preview.14.2! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-core-hosting Extensions / Hosting / AppBuilder / Startup fixed-in-6.0.200-preview.14.2 Look for this fix in 6.0.200-preview.14.2!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Disable Microsoft.Extensions.Logging by default in Release builds Proposal: Remove Maui's Dependency on Extensions.Hosting