c# - How solve circular reference in Caliburn.Micro -


i working caliburn.micro v2.0.1 on windows 8.1 unversal (winrt) project.

i followed caliburn.micro working winrt example.

my code looks follows:

app.xaml.cs

protected override void onlaunched(launchactivatedeventargs args) {     initialize();     displayrootviewfor<loginviewmodel>(); }  protected override void prepareviewfirst(frame rootframe) {     _container.registernavigationservice(rootframe); } 

loginviewmodel.cs

public loginviewmodel(inavigationservice navigationservice, ...) {    ... } 

the issue

the onlaunched called first.

initialize() configures winrt container.

  1. the displayrootviewfor<loginviewmodel> invokes instance of loginviewmodel , results in null exception because navigationservice has not yet been registered prepareviewfirst(frame)
  2. prepareviewfirst(frame) not yet called, having dependency on rootframe should configured onlaunched

thus loginviewmodel dependent on registernavigationservice , registernavigationservice dependent on displayrootviewfor<loginviewmodel>() dependent on loginviewmodel

is there way overcome circular reference issue?

register services in container before resolving views - way dependencies available in particular dependency injection container , can use servicelocator find them.

typically i've done in onstartup() method of app.xaml.cs.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -