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.
- the
displayrootviewfor<loginviewmodel>invokes instance ofloginviewmodel, results in null exception because navigationservice has not yet been registeredprepareviewfirst(frame) prepareviewfirst(frame)not yet called, having dependency onrootframeshould configuredonlaunched
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
Post a Comment