dadhi / DryIoc

DryIoc is fast, small, full-featured IoC Container for .NET
MIT License
1.01k stars 123 forks source link

Exception: Window already exists #645

Open ChristianM66 opened 3 months ago

ChristianM66 commented 3 months ago

Hello, I am using DryIoC in conjunction with IServiceColleciotn in net8 and Maui. When merging DryIoC and IServiceCollection using IContainer.Populate the following exception is thrown .

Without DryIoC and the Populate call, the exception does not occur.

Many thanks for your help

StackTrace at Microsoft.Maui.Controls.Window.Microsoft.Maui.IWindow.Created() at Microsoft.Maui.LifecycleEvents.AppHostBuilderExtensions.<>c.b2_0(Window window) at Microsoft.Maui.Platform.ApplicationExtensions.<>c__DisplayClass1_0.b1(OnWindowCreated del) at Microsoft.Maui.LifecycleEvents.LifecycleEventServiceExtensions.InvokeLifecycleEvents[TDelegate](IServiceProvider services, Action`1 action) at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Application platformApplication, IApplication application, OpenWindowRequest args) at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Application platformApplication, IApplication application, LaunchActivatedEventArgs args) at Microsoft.Maui.MauiWinUIApplication.OnLaunched(LaunchActivatedEventArgs args) at Microsoft.UI.Xaml.Application.Microsoft.UI.Xaml.IApplicationOverrides.OnLaunched(LaunchActivatedEventArgs args) at ABI.Microsoft.UI.Xaml.IApplicationOverrides.Do_Abi_OnLaunched_0(IntPtr thisPtr, IntPtr args)

dadhi commented 3 months ago

What is the exception message?

ChristianM66 commented 3 months ago

What is the exception message? The exception message is: Window already exists.

The error occurs under net8 regardless of which versions of DryIoC and DryIoc.Microsoft.DependencyInjection are used.

ioCManager encapsulates DryIoC.IContainer and is registered in DryIoContainer itself.

DryIoC: 5.4.3 DryIoc.Microsoft.DependencyInjection: 6.2.0

Configuration: private IocManager() { this.Container = new Container(_ => Rules.Default.WithConcreteTypeDynamicRegistrations(reuse: Reuse.Transient). With(Made.Of(FactoryMethod.ConstructorWithResolvableArguments)). WithFuncAndLazyWithoutRegistration(). WithTrackingDisposableTransients(). WithFactorySelector(Rules.SelectLastRegisteredFactory()). WithMicrosoftDependencyInjectionRules(). WithUseInterpretation()); }

or DryIoC: 6.0.0-preview-07 DryIoc.Microsoft.DependencyInjection: 8.0.0-preview-02

Configuration private IocManager() { Rules rules = DryIocAdapter.MicrosoftDependencyInjectionRules.WithConcreteTypeDynamicRegistrations(reuse: Reuse.Transient). With(Made.Of(FactoryMethod.ConstructorWithResolvableArguments)). WithFuncAndLazyWithoutRegistration(). WithTrackingDisposableTransients(). WithFactorySelector(Rules.SelectLastRegisteredFactory()). WithUseInterpretation();

this.Container = new Container(rules) }

When I call Populate (iocManager.Container.Populate(mauiAppBuilder.Services);) the exception is thrown.

I have been working successfully with DryIoc, Xamarin, netStandard, AspNet.Core since 2019. The error occurs with net8 and Maui.

No matter which platform (Windows Machine, Android, iOS) is used

dadhi commented 3 months ago

@ChristianM66

Thanks for the clarifying. Sadly, nor exception message, nor the stack trace contains any DryIoc related information. I would suggest to search MAUI code for specifics of the "Window already exists" condition.

Also in regard to the Rules.Default.WithConcreteTypeDynamicRegistrations(reuse: Reuse.Transient). Could you remove it and check again?

dadhi commented 3 months ago

@ChristianM66 Hi, I want to suggest trying DryIoc v6.0.0-preview-07 and check if the issue is reproducible.

dadhi commented 1 month ago

@ChristianM66 any updates on the issue?