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

Prism.Wpf: InitializeModules() should be called even if there's no shell #1601

Closed
dro123 opened this issue Oct 31, 2018 · 6 comments
Closed
Labels

Comments

@dro123
Copy link

dro123 commented Oct 31, 2018

Description

PrismApplicationBase.cs has this code right now:

            var shell = CreateShell();
            if (shell != null)
            {
                RegionManager.SetRegionManager(shell, _containerExtension.Resolve<IRegionManager>());
                RegionManager.UpdateRegions();
                InitializeShell(shell);
                InitializeModules();
            }

My application can also run as a consol application and in that case I want the modules even though there's no shell.

My current workaround is to call InitializeModules() myself in CreateShell() but this seems fragile.
Is there a reason InitializeModules() is only called if there's a shell?

Another point is that OnInitialized() crashes if there's no shell because MainWindow is null. So right now if there's no shell the application crashes if OnInitialized() is not overwritten and the base method not called.

@brianlagunas
Copy link
Member

brianlagunas commented Oct 31, 2018

What value are you getting out of Prism for WPF if you have no views/regions? Also, how do you prevent your modules from crashing since no regions exist in the app to inject any views? What exactly do these modules do?

@dro123
Copy link
Author

dro123 commented Oct 31, 2018

More or less only that it will load my modules.
The application is when run without command line parameters a normal WPF GUI application with regions and views. But I can specify command line parameters and in that case I don't need the UI part, just the module loading.

/edit:
Forget the other part of the question:
The modules still use the dependency injection of Unity that is initialized with Prism. There's a global flag that the modules check during intialization to not register any regions or views but do the other initialization stuff.
As an example I have module that does backups and this can be used from the UI (with views etc.) or from the command line.

@brianlagunas
Copy link
Member

Normally, I would say this isn't something I would allow. However, I do see that the old bootstrapper did allow for this, and the code changes are very minimal to support it. So I will merge your PR. Thanks for that by the way :)

brianlagunas added a commit that referenced this issue Oct 31, 2018
Load modules without a shell in WPF applications (#1601)
@brianlagunas
Copy link
Member

This has been fixed. You can test out the changes in the latest CI build on our MyGet feeed when the build has completed in about 20 minutes.

@dro123
Copy link
Author

dro123 commented Oct 31, 2018

Just checked 7.1.0.559-ci and it works fine.
Thank you!

@lock
Copy link

lock bot commented Jan 28, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants