Skip to content
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

Merged
merged 23 commits into from
Mar 22, 2021
Merged

Include Startup class #436

merged 23 commits into from
Mar 22, 2021

Conversation

jsuarezruiz
Copy link
Contributor

@jsuarezruiz jsuarezruiz commented Mar 5, 2021

  • Add IStartup interface
  • Add opt-in support for constructor DI
  • Attached the IMauiContext to the handlers so there is no need for App.Current internally.

/// 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);
Copy link
Contributor Author

@jsuarezruiz jsuarezruiz Mar 5, 2021

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()

Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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,

@jsuarezruiz jsuarezruiz marked this pull request as ready for review March 8, 2021 13:13
@rmarinho rmarinho requested review from Redth and rmarinho March 9, 2021 10:03
src/Core/src/Window.cs Outdated Show resolved Hide resolved
@jsuarezruiz
Copy link
Contributor Author

jsuarezruiz commented Mar 12, 2021

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.

Copy link

@chen495 chen495 left a comment

Choose a reason for hiding this comment

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

新手求救🆘

src/Core/src/Application.cs Outdated Show resolved Hide resolved
src/Core/src/Platform/iOS/MauiUIApplicationDelegate.cs Outdated Show resolved Hide resolved
src/Core/src/Platform/iOS/MauiUIApplicationDelegate.cs Outdated Show resolved Hide resolved
src/Core/src/Application.cs Outdated Show resolved Hide resolved
@jsuarezruiz jsuarezruiz changed the title Implement Startup and basic lifecycle events Include Startup class Mar 15, 2021
src/Core/src/Platform/Android/MauiApplication.cs Outdated Show resolved Hide resolved
src/Core/src/App.cs Outdated Show resolved Hide resolved
@mattleibow mattleibow mentioned this pull request Mar 17, 2021
@mattleibow
Copy link
Member

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.

#529

/// Create and configure a builder object.
/// </summary>
/// <returns>The new instance of the IAppHostBuilder.</returns>
public IAppHostBuilder CreateHostBuilder();
Copy link
Contributor Author

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.

Copy link
Member

@mattleibow mattleibow Mar 19, 2021

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.

Copy link
Contributor Author

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.

@rmarinho rmarinho merged commit d4a3de2 into main Mar 22, 2021
@rmarinho rmarinho deleted the startup branch March 22, 2021 14:45
@samhouts samhouts added legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor area-core-hosting Extensions / Hosting / AppBuilder / Startup area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter area-controls-button Button, ImageButton area-controls-editor Editor area-controls-entry Entry area-controls-label Label, Span area-controls-progressbar ProgressBar area-controls-slider Slider area-controls-switch Switch platform/android 🤖 platform/iOS 🍎 labels Jul 11, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 27, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-button Button, ImageButton area-controls-editor Editor area-controls-entry Entry area-controls-label Label, Span area-controls-progressbar ProgressBar area-controls-slider Slider area-controls-switch Switch area-core-hosting Extensions / Hosting / AppBuilder / Startup area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter fixed-in-6.0.100-preview.3.2 platform/android 🤖 platform/iOS 🍎
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants