Skip to content

Commit

Permalink
Revert "[core] use factory methods for registering services (#16741)"
Browse files Browse the repository at this point in the history
This reverts commit b0bba51.

# Conflicts:
#	src/Controls/src/Xaml/Hosting/AppHostBuilderExtensions.cs
#	src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt
  • Loading branch information
PureWeen committed Aug 29, 2023
1 parent fb2fc87 commit 292cbc5
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 221 deletions.
18 changes: 1 addition & 17 deletions eng/BannedSymbols.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,2 @@
M:Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddSingleton`2(Microsoft.Extensions.DependencyInjection.IServiceCollection);Use a Factory method to create the service instead
M:Android.Content.Res.ColorStateList.#ctor(System.Int32[][],System.Int32[]);Use Microsoft.Maui.PlatformInterop.Get*ColorStateList() Java methods instead
M:Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddScoped(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Type,System.Type);Use a Factory method to register the service instead
M:Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddScoped`2(Microsoft.Extensions.DependencyInjection.IServiceCollection);Use a Factory method to register the service instead
M:Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddSingleton(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Type,System.Type);Use a Factory method to register the service instead
M:Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddSingleton`2(Microsoft.Extensions.DependencyInjection.IServiceCollection);Use a Factory method to register the service instead
M:Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddTransient(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Type,System.Type);Use a Factory method to register the service instead
M:Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddTransient`2(Microsoft.Extensions.DependencyInjection.IServiceCollection);Use a Factory method to register the service instead
M:Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddScoped(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Type,System.Type);Use a Factory method to register the service instead
M:Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddScoped`2(Microsoft.Extensions.DependencyInjection.IServiceCollection);Use a Factory method to register the service instead
M:Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Type,System.Type);Use a Factory method to register the service instead
M:Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton`2(Microsoft.Extensions.DependencyInjection.IServiceCollection);Use a Factory method to register the service instead
M:Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddTransient(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Type,System.Type);Use a Factory method to register the service instead
M:Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddTransient`2(Microsoft.Extensions.DependencyInjection.IServiceCollection);Use a Factory method to register the service instead
M:Microsoft.Maui.Hosting.ImageSourceServiceCollectionExtensions.AddService`2(Microsoft.Maui.Hosting.IImageSourceServiceCollection);Use a Factory method to register the service instead
M:Microsoft.Maui.Hosting.MauiHandlersCollectionExtensions.AddHandler(Microsoft.Maui.Hosting.IMauiHandlersCollection,System.Type,System.Type);Use a Factory method to register the service instead
M:Microsoft.Maui.Hosting.MauiHandlersCollectionExtensions.AddHandler`2(Microsoft.Maui.Hosting.IMauiHandlersCollection);Use a Factory method to register the service instead
M:Microsoft.Maui.Hosting.MauiHandlersCollectionExtensions.TryAddHandler(Microsoft.Maui.Hosting.IMauiHandlersCollection,System.Type,System.Type);Use a Factory method to register the service instead
M:Microsoft.Maui.Hosting.MauiHandlersCollectionExtensions.TryAddHandler`2(Microsoft.Maui.Hosting.IMauiHandlersCollection);Use a Factory method to register the service instead
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static IMauiBlazorWebViewBuilder AddMauiBlazorWebView(this IServiceCollec
services.TryAddSingleton(new BlazorWebViewDeveloperTools { Enabled = false });
#if WEBVIEW2_MAUI
services.TryAddSingleton<MauiBlazorMarkerService>();
services.ConfigureMauiHandlers(static handlers => handlers.AddHandler<IBlazorWebView>(_ => new BlazorWebViewHandler()));
services.ConfigureMauiHandlers(static handlers => handlers.AddHandler<IBlazorWebView, BlazorWebViewHandler>());
return new MauiBlazorWebViewBuilder(services);
#elif WEBVIEW2_WINFORMS
services.TryAddSingleton<WindowsFormsBlazorMarkerService>();
Expand Down
16 changes: 8 additions & 8 deletions src/Compatibility/Core/src/MauiHandlersCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public static IMauiHandlersCollection TryAddCompatibilityRenderer(this IMauiHand
Internals.Registrar.Registered.Register(controlType, rendererType);

#if PLATFORM
#pragma warning disable CS0612, RS0030 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
handlersCollection.TryAddHandler(controlType, typeof(RendererToHandlerShim));
#pragma warning restore CS0612, RS0030 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
#endif

return handlersCollection;
Expand All @@ -28,9 +28,9 @@ public static IMauiHandlersCollection AddCompatibilityRenderer(this IMauiHandler
Internals.Registrar.Registered.Register(controlType, rendererType);

#if PLATFORM
#pragma warning disable CS0612, RS0030 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
handlersCollection.AddHandler(controlType, typeof(RendererToHandlerShim));
#pragma warning restore CS0612, RS0030 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
#endif

return handlersCollection;
Expand All @@ -44,9 +44,9 @@ public static IMauiHandlersCollection AddCompatibilityRenderer<TControlType, TMa
Internals.Registrar.Registered.Register(typeof(TControlType), typeof(TRenderer));

#if PLATFORM
#pragma warning disable CS0612, RS0030 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
handlersCollection.AddHandler<TMauiType, RendererToHandlerShim>();
#pragma warning restore CS0612, RS0030 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
#endif
return handlersCollection;
}
Expand Down Expand Up @@ -76,9 +76,9 @@ public static IMauiHandlersCollection AddCompatibilityRenderers(this IMauiHandle
}, default(InitializationFlags),
(result) =>
{
#pragma warning disable CS0612, RS0030 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
handlersCollection?.TryAddHandler(result.target, typeof(RendererToHandlerShim));
#pragma warning restore CS0612, RS0030 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
});
#endif

Expand Down
6 changes: 3 additions & 3 deletions src/Controls/Maps/src/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public static MauiAppBuilder UseMauiMaps(this MauiAppBuilder builder)
public static IMauiHandlersCollection AddMauiMaps(this IMauiHandlersCollection handlersCollection)
{
#if __ANDROID__ || __IOS__
handlersCollection.AddHandler<Map>(_ => new MapHandler());
handlersCollection.AddHandler<Pin>(_ => new MapPinHandler());
handlersCollection.AddHandler<MapElement>(_ => new MapElementHandler());
handlersCollection.AddHandler<Map, MapHandler>();
handlersCollection.AddHandler<Pin, MapPinHandler>();
handlersCollection.AddHandler<MapElement, MapElementHandler>();
#endif
return handlersCollection;
}
Expand Down
153 changes: 71 additions & 82 deletions src/Controls/src/Xaml/Hosting/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,112 +62,101 @@ public static partial class AppHostBuilderExtensions

public static IMauiHandlersCollection AddMauiControlsHandlers(this IMauiHandlersCollection handlersCollection)
{
handlersCollection.AddHandler<CollectionView>(_ => new CollectionViewHandler());
handlersCollection.AddHandler<CarouselView>(_ => new CarouselViewHandler());
handlersCollection.AddHandler<Application>(_ => new ApplicationHandler());
handlersCollection.AddHandler<ActivityIndicator>(_ => new ActivityIndicatorHandler());
handlersCollection.AddHandler<BoxView>(_ => new BoxViewHandler());
handlersCollection.AddHandler<Button>(_ => new ButtonHandler());
handlersCollection.AddHandler<CheckBox>(_ => new CheckBoxHandler());
handlersCollection.AddHandler<DatePicker>(_ => new DatePickerHandler());
handlersCollection.AddHandler<Editor>(_ => new EditorHandler());
handlersCollection.AddHandler<Entry>(_ => new EntryHandler());
handlersCollection.AddHandler<GraphicsView>(_ => new GraphicsViewHandler());
handlersCollection.AddHandler<Image>(_ => new ImageHandler());
handlersCollection.AddHandler<Label>(_ => new LabelHandler());
handlersCollection.AddHandler<Layout>(_ => new LayoutHandler());
handlersCollection.AddHandler<Picker>(_ => new PickerHandler());
handlersCollection.AddHandler<ProgressBar>(_ => new ProgressBarHandler());
handlersCollection.AddHandler<ScrollView>(_ => new ScrollViewHandler());
handlersCollection.AddHandler<SearchBar>(_ => new SearchBarHandler());
handlersCollection.AddHandler<Slider>(_ => new SliderHandler());
handlersCollection.AddHandler<Stepper>(_ => new StepperHandler());
handlersCollection.AddHandler<Switch>(_ => new SwitchHandler());
handlersCollection.AddHandler<TimePicker>(_ => new TimePickerHandler());
handlersCollection.AddHandler<Page>(_ => new PageHandler());
handlersCollection.AddHandler<WebView>(_ => new WebViewHandler());
handlersCollection.AddHandler<Border>(_ => new BorderHandler());
handlersCollection.AddHandler<IContentView>(_ => new ContentViewHandler());
handlersCollection.AddHandler<Shapes.Ellipse>(_ => new ShapeViewHandler());
handlersCollection.AddHandler<Shapes.Line>(_ => new LineHandler());
handlersCollection.AddHandler<Shapes.Path>(_ => new PathHandler());
handlersCollection.AddHandler<Shapes.Polygon>(_ => new PolygonHandler());
handlersCollection.AddHandler<Shapes.Polyline>(_ => new PolylineHandler());
handlersCollection.AddHandler<Shapes.Rectangle>(_ => new RectangleHandler());
handlersCollection.AddHandler<Shapes.RoundRectangle>(_ => new RoundRectangleHandler());
handlersCollection.AddHandler<Window>(_ => new WindowHandler());
handlersCollection.AddHandler<ImageButton>(_ => new ImageButtonHandler());
handlersCollection.AddHandler<IndicatorView>(_ => new IndicatorViewHandler());
handlersCollection.AddHandler<RadioButton>(_ => new RadioButtonHandler());
handlersCollection.AddHandler<RefreshView>(_ => new RefreshViewHandler());
handlersCollection.AddHandler<SwipeItem>(_ => new SwipeItemMenuItemHandler());
handlersCollection.AddHandler<SwipeView>(_ => new SwipeViewHandler());
handlersCollection.AddHandler<CollectionView, CollectionViewHandler>();
handlersCollection.AddHandler<CarouselView, CarouselViewHandler>();
handlersCollection.AddHandler<Application, ApplicationHandler>();
handlersCollection.AddHandler<ActivityIndicator, ActivityIndicatorHandler>();
handlersCollection.AddHandler<BoxView, BoxViewHandler>();
handlersCollection.AddHandler<Button, ButtonHandler>();
handlersCollection.AddHandler<CheckBox, CheckBoxHandler>();
handlersCollection.AddHandler<DatePicker, DatePickerHandler>();
handlersCollection.AddHandler<Editor, EditorHandler>();
handlersCollection.AddHandler<Entry, EntryHandler>();
handlersCollection.AddHandler<GraphicsView, GraphicsViewHandler>();
handlersCollection.AddHandler<Image, ImageHandler>();
handlersCollection.AddHandler<Label, LabelHandler>();
handlersCollection.AddHandler<Layout, LayoutHandler>();
handlersCollection.AddHandler<Picker, PickerHandler>();
handlersCollection.AddHandler<ProgressBar, ProgressBarHandler>();
handlersCollection.AddHandler<ScrollView, ScrollViewHandler>();
handlersCollection.AddHandler<SearchBar, SearchBarHandler>();
handlersCollection.AddHandler<Slider, SliderHandler>();
handlersCollection.AddHandler<Stepper, StepperHandler>();
handlersCollection.AddHandler<Switch, SwitchHandler>();
handlersCollection.AddHandler<TimePicker, TimePickerHandler>();
handlersCollection.AddHandler<Page, PageHandler>();
handlersCollection.AddHandler<WebView, WebViewHandler>();
handlersCollection.AddHandler<Border, BorderHandler>();
handlersCollection.AddHandler<IContentView, ContentViewHandler>();
handlersCollection.AddHandler<Shapes.Ellipse, ShapeViewHandler>();
handlersCollection.AddHandler<Shapes.Line, LineHandler>();
handlersCollection.AddHandler<Shapes.Path, PathHandler>();
handlersCollection.AddHandler<Shapes.Polygon, PolygonHandler>();
handlersCollection.AddHandler<Shapes.Polyline, PolylineHandler>();
handlersCollection.AddHandler<Shapes.Rectangle, RectangleHandler>();
handlersCollection.AddHandler<Shapes.RoundRectangle, RoundRectangleHandler>();
handlersCollection.AddHandler<Window, WindowHandler>();
handlersCollection.AddHandler<ImageButton, ImageButtonHandler>();
handlersCollection.AddHandler<IndicatorView, IndicatorViewHandler>();
handlersCollection.AddHandler<RadioButton, RadioButtonHandler>();
handlersCollection.AddHandler<RefreshView, RefreshViewHandler>();
handlersCollection.AddHandler<SwipeItem, SwipeItemMenuItemHandler>();
handlersCollection.AddHandler<SwipeView, SwipeViewHandler>();

#pragma warning disable CA1416 // 'MenuBarHandler', MenuFlyoutSubItemHandler, MenuFlyoutSubItemHandler, MenuBarItemHandler is only supported on: 'ios' 13.0 and later
handlersCollection.AddHandler<MenuBar>(_ => new MenuBarHandler());
handlersCollection.AddHandler<MenuFlyoutSubItem>(_ => new MenuFlyoutSubItemHandler());
handlersCollection.AddHandler<MenuFlyoutSeparator>(_ => new MenuFlyoutSeparatorHandler());
handlersCollection.AddHandler<MenuFlyoutItem>(_ => new MenuFlyoutItemHandler());
handlersCollection.AddHandler<MenuBarItem>(_ => new MenuBarItemHandler());
handlersCollection.AddHandler<MenuBar, MenuBarHandler>();
handlersCollection.AddHandler<MenuFlyoutSubItem, MenuFlyoutSubItemHandler>();
handlersCollection.AddHandler<MenuFlyoutSeparator, MenuFlyoutSeparatorHandler>();
handlersCollection.AddHandler<MenuFlyoutItem, MenuFlyoutItemHandler>();
handlersCollection.AddHandler<MenuBarItem, MenuBarItemHandler>();
#pragma warning restore CA1416

#if WINDOWS || ANDROID || IOS || MACCATALYST || TIZEN
handlersCollection.AddHandler<ListView>(svc => new Handlers.Compatibility.ListViewRenderer(
#if ANDROID
svc.GetRequiredService<Android.Content.Context>()
#endif
));
handlersCollection.AddHandler(typeof(ListView), typeof(Handlers.Compatibility.ListViewRenderer));
#if !TIZEN
handlersCollection.AddHandler<ImageCell>(_ => new Handlers.Compatibility.ImageCellRenderer());
handlersCollection.AddHandler<EntryCell>(_ => new Handlers.Compatibility.EntryCellRenderer());
handlersCollection.AddHandler<TextCell>(_ => new Handlers.Compatibility.TextCellRenderer());
handlersCollection.AddHandler<ViewCell>(_ => new Handlers.Compatibility.ViewCellRenderer());
handlersCollection.AddHandler<SwitchCell>(_ => new Handlers.Compatibility.SwitchCellRenderer());
#endif
handlersCollection.AddHandler<TableView>(svc => new Handlers.Compatibility.TableViewRenderer(
#if ANDROID
svc.GetRequiredService<Android.Content.Context>()
#endif
));
handlersCollection.AddHandler<Frame>(svc => new Handlers.Compatibility.FrameRenderer(
#if ANDROID
svc.GetRequiredService<Android.Content.Context>()
handlersCollection.AddHandler(typeof(Cell), typeof(Handlers.Compatibility.CellRenderer));
handlersCollection.AddHandler(typeof(ImageCell), typeof(Handlers.Compatibility.ImageCellRenderer));
handlersCollection.AddHandler(typeof(EntryCell), typeof(Handlers.Compatibility.EntryCellRenderer));
handlersCollection.AddHandler(typeof(TextCell), typeof(Handlers.Compatibility.TextCellRenderer));
handlersCollection.AddHandler(typeof(ViewCell), typeof(Handlers.Compatibility.ViewCellRenderer));
handlersCollection.AddHandler(typeof(SwitchCell), typeof(Handlers.Compatibility.SwitchCellRenderer));
#endif
));
handlersCollection.AddHandler(typeof(TableView), typeof(Handlers.Compatibility.TableViewRenderer));
handlersCollection.AddHandler(typeof(Frame), typeof(Handlers.Compatibility.FrameRenderer));
#endif

#if WINDOWS || MACCATALYST
handlersCollection.AddHandler<MenuFlyout>(_ => new MenuFlyoutHandler());
handlersCollection.AddHandler(typeof(MenuFlyout), typeof(MenuFlyoutHandler));
#endif

#if IOS || MACCATALYST
handlersCollection.AddHandler<NavigationPage>(_ => new Handlers.Compatibility.NavigationRenderer());
handlersCollection.AddHandler<TabbedPage>(_ => new Handlers.Compatibility.TabbedRenderer());
handlersCollection.AddHandler<FlyoutPage>(_ => new Handlers.Compatibility.PhoneFlyoutPageRenderer());
handlersCollection.AddHandler(typeof(NavigationPage), typeof(Handlers.Compatibility.NavigationRenderer));
handlersCollection.AddHandler(typeof(TabbedPage), typeof(Handlers.Compatibility.TabbedRenderer));
handlersCollection.AddHandler(typeof(FlyoutPage), typeof(Handlers.Compatibility.PhoneFlyoutPageRenderer));
#endif

#if ANDROID || IOS || MACCATALYST || TIZEN
handlersCollection.AddHandler<SwipeItemView>(_ => new SwipeItemViewHandler());
handlersCollection.AddHandler<SwipeItemView, SwipeItemViewHandler>();
#if ANDROID || IOS || MACCATALYST
handlersCollection.AddHandler<Shell>(_ => new ShellRenderer());
handlersCollection.AddHandler<Shell, ShellRenderer>();
#else
handlersCollection.AddHandler<Shell>(_ => new ShellHandler());
handlersCollection.AddHandler<ShellItem>(_ => new ShellItemHandler());
handlersCollection.AddHandler<ShellSection>(_ => new ShellSectionHandler());
handlersCollection.AddHandler<Shell, ShellHandler>();
handlersCollection.AddHandler<ShellItem, ShellItemHandler>();
handlersCollection.AddHandler<ShellSection, ShellSectionHandler>();
#endif
#endif
#if WINDOWS || ANDROID || TIZEN
handlersCollection.AddHandler<NavigationPage>(_ => new NavigationViewHandler());
handlersCollection.AddHandler<Toolbar>(_ => new ToolbarHandler());
handlersCollection.AddHandler<FlyoutPage>(_ => new FlyoutViewHandler());
handlersCollection.AddHandler<TabbedPage>(_ => new TabbedViewHandler());
handlersCollection.AddHandler<NavigationPage, NavigationViewHandler>();
handlersCollection.AddHandler<Toolbar, ToolbarHandler>();
handlersCollection.AddHandler<FlyoutPage, FlyoutViewHandler>();
handlersCollection.AddHandler<TabbedPage, TabbedViewHandler>();
#endif

#if WINDOWS
handlersCollection.AddHandler<ShellItem>(_ => new ShellItemHandler());
handlersCollection.AddHandler<ShellSection>(_ => new ShellSectionHandler());
handlersCollection.AddHandler<ShellContent>(_ => new ShellContentHandler());
handlersCollection.AddHandler<Shell>(_ => new ShellHandler());
handlersCollection.AddHandler<ShellItem, ShellItemHandler>();
handlersCollection.AddHandler<ShellSection, ShellSectionHandler>();
handlersCollection.AddHandler<ShellContent, ShellContentHandler>();
handlersCollection.AddHandler<Shell, ShellHandler>();
#endif
return handlersCollection;
}
Expand Down
1 change: 0 additions & 1 deletion src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<RootNamespace>Microsoft.Maui.DeviceTests</RootNamespace>
<AssemblyName>Microsoft.Maui.Controls.DeviceTests</AssemblyName>
<NoWarn>$(NoWarn),CA1416</NoWarn>
<IsTestProject>true</IsTestProject>
<!-- Disable multi-RID builds to workaround a parallel build issue -->
<RuntimeIdentifier Condition="$(TargetFramework.Contains('-maccatalyst'))">maccatalyst-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="$(TargetFramework.Contains('-maccatalyst')) and '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'arm64'">maccatalyst-arm64</RuntimeIdentifier>
Expand Down
Loading

0 comments on commit 292cbc5

Please sign in to comment.