2016-10-11 9 views
0

プリズムMVVMフレームワークを使用している私のxamarinフォームアプリケーションでは、IoCコンテナはどのように使うべきですか? 私たちはのIoCを解決し、app.xaml.cs.に初期化する必要があると思う何Xamarinフォーム:プリズム - ユニティIoCの使用に関する問題?

Container.Resolve<Interface,Implentation> 

はありませんしかし、私はそれを行うための適切な方法を見つけることができません。 誰か助けてくれますか?

UPDATE:

PAGE:

<?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="CoC.Core.Views.MenuPage"> 
    <ContentPage.Content> 
      <ListView x:Name="info" 
      SeparatorVisibility="None" 
      SeparatorColor="Transparent" 
      HasUnevenRows="false" 
      RowHeight="50" BackgroundColor="#485366" > 
     <ListView.ItemTemplate> 
        <DataTemplate> 
         <!--<ImageCell Text="{Binding Title}" ImageSource="{Binding IconSource}" /> --> 
         <ViewCell> 
          <!--<Label Text="{Binding Title}" />--> 
         </ViewCell> 
        </DataTemplate> 
       </ListView.ItemTemplate> 
      </ListView> 
    </ContentPage.Content> 
</ContentPage> 

のViewModel:

using Prism.Commands; 
using Prism.Mvvm; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Collections.ObjectModel; 
using Prism.Navigation; 

namespace CoC.Core.ViewModels 
{ 
    public class MenuPageViewModel : BindableBase , INavigationAware 
    { 
     IMenuList _menuList; 
     public ObservableCollection<MenuItem> ConductList { get; set; } 

     public void OnNavigatedFrom(NavigationParameters parameters) 
     { 
      //throw new NotImplementedException(); 
     } 

     public void OnNavigatedTo(NavigationParameters parameters) 
     { 
      //throw new NotImplementedException(); 
     } 

     public MenuPageViewModel(IMenuList MenuList) 
     { 
      _menuList = MenuList; 
      ConductList = _menuList.GetMenuList(); 
     } 

    } 
} 

APP:

using Prism.Unity; 
using CoC.Core.Views; 

namespace CoC.Core 
{ 
    public partial class App : PrismApplication 
    { 
     protected override void OnInitialized() 
     { 
      InitializeComponent(); 

      //NavigationService.NavigateAsync("MainPage?title=Hello%20from%20Xamarin.Forms"); 
      NavigationService.NavigateAsync("MenuPage"); 
     } 

     protected override void RegisterTypes() 
     { 
      Container.RegisterTypeForNavigation<MainPage>(); 
      Container.RegisterTypeForNavigation<RootPage>(); 
      Container.RegisterTypeForNavigation<MenuPage>(); 
     } 
    } 
} 

私はこのコードを実行すると、 IOSのプロのMain.csでエラーが発生しています エラー: Foundation.MonoTouchException NSInternalLnconistencyException理由:アプリケーションウィンドウには、アプリケーションの最後にルートビューコントローラが必要です。

+0

Visual Studio Extension for Prismテンプレートパックをインストールし、それを使用してソリューション –

+0

を作成しました。 – TheDeveloper

+0

コンテナを使用してIMenuListインターフェイスをクラスに登録する –

答えて

1

あなたが探しているのはUnityの拡張メソッドです。コードファイルにusing Microsoft.Practices.Unity名前空間を追加する必要があります。 Container.Register<IService,MyService>()を使用してサービスを登録できます。

+0

名前空間を追加しました。 UnityコンテナはRegisterを持たず、RegisterType関数を持っていました。だから、私は 'container.RegisterType ();'を追加しましたが、私はまだ同じエラーが発生しています。 – TheDeveloper

+0

あなたは何か間違っている。あなたのコードのどこかに問題があるかもしれません。 –

+0

あなたは正しかった。それを解決しました。 – TheDeveloper

関連する問題