2

I created a Prism Unity App (from the prism extension pack - really nice), added 2 new views and set up basic navigation between the views. This all worked fine without any hiccups.

What I really want is to use DryIoc (company policy). So I proceeded to remove the unity packages (Unity and Prism.Unity.Forms) and installed the DryIoc Packages (DryIoc and Prism.DryIoc.Forms). Fixed the App.xaml to use the correct namespace (xmlns:prism="clr-namespace:Prism.DryIoc;assembly=Prism.DryIoc.Forms") and alos fixed all the other references to use DryIoc and not the Unity References.

This all compiles and runs without any exceptions. But when I debug it is clear that the AutoWireup does not work as expected (at least as I expect it to). The breakpoint in the ViewModel's constructor (or any other place) is not hit and the Title bindings does not pull through.

Is there a Configuration/Setup or reference that I am missing?

My Code: App.xaml:

<?xml version="1.0" encoding="utf-8" ?><prism:PrismApplication xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                    xmlns:prism="clr-namespace:Prism.DryIoc;assembly=Prism.DryIoc.Forms"
                    x:Class="XamFormsPrism.App"></prism:PrismApplication>

App.xaml.cs:

public partial class App : Prism.DryIoc.PrismApplication
{
    public App(IPlatformInitializer initializer = null) : base(initializer) { }

    protected override void ConfigureContainer()
    {
        base.ConfigureContainer();            

    }
    protected override void OnInitialized()
    {
        this.InitializeComponent();

        this.NavigationService.NavigateAsync(NavigationLinks.MainPage);
    }

    protected override void RegisterTypes()
    {
        this.Container.RegisterTypeForNavigation<MainPage>();
        this.Container.RegisterTypeForNavigation<ViewA>();
        this.Container.RegisterTypeForNavigation<ViewB>();
    }
}

MainPage.xaml:

<?xml version="1.0" encoding="utf-8" ?><ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
         prism:ViewModelLocator.AutowireViewModel="True"
         x:Class="XamFormsPrism.Views.MainPage"
         Title="MainPage"><StackLayout HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="{Binding Title}" />
<Button Text="{Binding NavigateText}" Command="{Binding NavigateCommand}" /> </StackLayout></ContentPage>

MainPageViewModel.cs:

public class MainPageViewModel : BindableBase, INavigationAware
{
    private INavigationService navigationService = null;

    private string _title = "Jose Cuervo";
    public string Title
    {
        get { return _title; }
        set { SetProperty(ref _title, value); }
    }

    public DelegateCommand NavigateCommand { get; private set; }

    public MainPageViewModel(INavigationService navigationService)
    {
        this.navigationService = navigationService;
        this.NavigateCommand = new DelegateCommand(this.navigate, this.canNavigate);
    }

    private void navigate()
    {
        this.navigationService.NavigateAsync("ViewA");
    }

    private bool canNavigate()
    {
        return true;
    }

    public void OnNavigatedFrom(NavigationParameters parameters)
    {

    }

    public void OnNavigatedTo(NavigationParameters parameters)
    {
        if (parameters.ContainsKey("title"))
            Title = (string)parameters["title"] + " and Prism";
    }
}

As seen above I use the standard naming convention of PageName & PageNameViewModel with the AutoWireUp set to True.

This all worked fine with Unity but I am missing something in DryIoc...but what escapes me.

I have searched the entire project, there is no reference or trace left of Unity.

Any help is much appreciated.

Van
  • 600
  • 4
  • 12
  • I am not a pro in Prism, but here is the article describing breaking changes in Prism DryIoc for Xamarin Forms: http://brianlagunas.com/prism-for-xamarin-forms-6-2-release/ – dadhi Aug 23 '16 at 20:11
  • Thanks. But from that article there is a link to Prism.DryIoc.Forms which is now supported in Prism 6.2. I have read that article a couple of times and could not get any wiser about why I am getting this issue. – Van Aug 24 '16 at 06:40
  • Did you tried some code mutations: like removing Autowire property, or changing RegForNav with explicit V / VM types? May be you have a sample proj, so I can check it too? if I have time – dadhi Aug 24 '16 at 07:03
  • Hi @dadhi, your help is appreciated. I added my test app to bitbucket (https://bitbucket.org/ivanvh/prism.dryioc.forms-test). I think I set up access for you correctly. Pleas let me know if not. One thing I can mention on the Prism.DryIoc.Forms is that the dependency on DryIoc is on the DryIoc package and not the DryIoc.dll package. But the app does not compile if you don not add the DryIoc.dll package. Maybe I am doing something wrong there? Should I not include the DryIoc.dll package... Your help is appreciated – Van Aug 24 '16 at 08:57
  • I have an access, thanks. – dadhi Aug 24 '16 at 12:24
  • Have problems with app deployment, not sure how to solve. So, no fast feedback from me :-( – dadhi Aug 26 '16 at 07:20
  • I finally had time again to have a look at this. If I explicit register the ViewModels in the container everything works fine. So I am guessing that there is either a rule missing for the DryIoC container or when using DryIoC you have to explicitly register the ViewModels. – Van Sep 02 '16 at 12:12
  • Huh, ok. You may use RegisterMany to batch register your vms, and a bit simplify your life. – dadhi Sep 02 '16 at 17:16

1 Answers1

1

I finally had time again to have a look at this. If I explicit register the ViewModels in the container everything works fine. So I am guessing that there is either a rule missing for the DryIoC container or when using DryIoC you have to explicitly register the ViewModels.

Van
  • 600
  • 4
  • 12
  • It happened the same for me using the latest 7.X beta I had to add Viemodel using the containerRegistry.RegisterForNavigation(); method for it to work. – alexsaez Dec 22 '17 at 13:29