Recommend LoadAssembliesOnStartup.Fody in README
Closed this issue · 5 comments
In Visual Studio, create a new WPF Application project that does not use LoadAssembliesOnStartup.Fody. Somewhere in the code of the new project, try to resolve IWizardService
with the following code snippet:
Type wizardServiceType = typeof(Orc.Wizard.IWizardService);
object wizardService = serviceLocator.ResolveType(wizardServiceType) as Orc.Wizard.IWizardService;
This will fail with a TypeNotRegisteredException
. To an experienced Catel developer the reason might be obvious. As a newbie, however, the failure is completely mystifying. After delving deeper into the source code of Orc.Wizard, and then later Catel.Core and Catel.MVVM, the reason becomes clear:
Orc.Wizard.WizardService
cannot be instantiated by the service locator because the WizardService
constructor requires an IUIVisualizerService
object, which the service locator is unable to provide because that service has never been registered.
After the inexperienced Catel newbie adds LoadAssembliesOnStartup.Fody to the project, everything works fine, because the Fody add-in triggers the module initializer in Catel.MVVM, which causes ViewModelServiceHelper.RegisterDefaultViewModelServices()
to be called, which in turn registers IUIVisualizerService
with the service locator. Neat.
To lower the entry bar for Catel newbies, I suggest that the README is enhanced with instructions to make sure that LoadAssembliesOnStartup.Fody is used. If generous, an explanation might be added so that the intelligent developer learns why he has to do this.
Excellent idea. Interesting in doing a PR?
I thought you might ask :-) Sure, I'll try to write something. I tend to be verbose, so let me know in advance if you want me to keep it short.
I hope to re-use this in multiple readmes (actually all orc.* packages), so just a "How to solve TypeNotRegistered" of about 10-20 lines?
Merged so I can close this one.
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.