-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Include Startup class #436
Conversation
/// Configure are called by the .NET MAUI Core runtime when the app starts. | ||
/// </summary> | ||
/// <param name="appBuilder">Defines a class that provides the mechanisms to configure an application's dependencies.</param> | ||
void Configure(IAppHostBuilder appBuilder); |
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.
@rmarinho What do you think? Maybe we should create directly the Builder? IAppHostBuilder CreateBuilder()
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.
We might want both? I think we want to configure it still but have a:
public virtual IAppHostBuilder CreateBuilder() => new DefaultAppHostBuilder();
So we can choose to override it, or let the default implementation be created.
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 agree with @Redth , we want it virtual that calls the default builder, user can override
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 would add a new Method that is CreateBuilder that returns CreateDefaultBuilder.
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.
In ASP.NET, the user instantiates the builder in Program.cs and then configures it in Startup.cs. Now this is not quite possible here, but we can have our Startup have a "get builder" method instead of configure? Or maybe we should have an additional IHostBuilderStartup
interface that will allow the user top optionally implement it and construct the builder?
What if the user does not want our defaults? For example, not to register all the MAUI views and not to use the fonts. And, this might have future implications. Just as we had launch options in Forms to control what was registered, we may need this so users can not have to pass in some options, but rather control the whole thing,
To facilitate the review and feedback about Startup class, native lifecycle events and cross platform lifecycle events (besides being actually related but different functionality) I am going to split this PR into smaller PRs.
|
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.
新手求救🆘
Based on my thoughts and also to play around a bit, I made this PR to this PR :) with what I was thinking. Good thing I did do this as some ideas were a bit out there and actually couldn't work or did not feel nice when using it. This PR is one thought process I had so maybe it is better or worse and we can either merge and iterate or I can rework it. |
/// Create and configure a builder object. | ||
/// </summary> | ||
/// <returns>The new instance of the IAppHostBuilder.</returns> | ||
public IAppHostBuilder CreateHostBuilder(); |
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.
@mattleibow I've added IHostBuilderStartup
. To create a custom HostBuilder only need to implement this interface in Startup. However, I am thinking in a better approach, use a default interface method: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/default-interface-methods
In IStartup
, include the CreateHostBuilder method, with a base implementation.
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.
Does this work in classic Xamarin? I am thinking for local dev purposes until tooling becomes more net6 friendly. But yeah, a default implementation is certainly better.
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.
Not, is not working for now.
IStartup
interfaceIMauiContext
to the handlers so there is no need forApp.Current
internally.