Mef OnImportsSatisfied() Equivalent in Unity?...

Sep 2, 2014 at 4:52 AM
Edited Sep 2, 2014 at 5:06 AM

OS: Window 8.1
Development: WinRT, WinPhone

Is there Mef OnImportsSatisfied() equivalent other than using the Loaded Event handler in Code-Behind? My object is to initialize some IObservable's to capture some Control Events and I don't want to add a property to the ViewModel to access the prism:VisualStateAwarePage. And, I'm ViewModelLocator.AutoWireViewModel="true" for my ViewModel instantiation.

In MEF I was doing this for my Desktop App:
public void OnImportsSatisfied()
    // IPartImportsSatisfiedNotification is useful when you want to coordinate doing some work
    // with imported parts independent of when the UI is visible.
    Debug.WriteLine("Shell OnImportsSatisfied instantiation");

    IObservableService ObservableService = ServiceLocator.Current.GetInstance<IObservableService>();

    //ObservableService.RibbonWindowLoadedEventArgs =
    //    Observable.FromEventPattern<object, EventArgs>(this.NatsarTurahStudyMaster, "ContentRendered");
    ////    Observable.FromEventPattern<object, RoutedEventArgs>(this.NatsarTurahStudyMaster, "Loaded");
    //ObservableService.DisposableRibbonWindowLoaded =
    //    ObservableService.RibbonWindowLoadedEventArgs.Subscribe(evt => this.ViewModel.OnNatsarLoaded(evt.Sender, evt.EventArgs));

    ObservableService.RibbonWindowClosingEventArgs =
        Observable.FromEventPattern<object, CancelEventArgs>(this.NatsarTurahStudyMaster, "Closing");
    ObservableService.RibbonWindowClosingEventArgs.Subscribe(evt => this.ViewModel.OnNatsarClosing(evt.Sender, evt.EventArgs));

    ObservableService.RibbonWindowClosedEventArgs =
        Observable.FromEventPattern<object, EventArgs>(this.NatsarTurahStudyMaster, "Closed");
    ObservableService.RibbonWindowClosedEventArgs.Subscribe(evt => this.ViewModel.OnNatsarClosed(evt.Sender, evt.EventArgs));
What is the best to accomplish this same routine in Unity on the WinRT/Phone 8.1?

Sep 2, 2014 at 12:31 PM
There is no analogous functionality in Unity.

If you want to implement something similar you would have to code it yourself and maintain the logic of when certain dependencies have been registered. You could do this with a Unity container extension that raises an event.

Randy Levy
Enterprise Library support engineer
Support How-to
Sep 3, 2014 at 3:19 AM
Ok thanks!... Appreciation your reply!... :)