프리즘 MVVM 프레임 워크를 사용하는 제 xamarin 폼 앱에서 IoC 컨테이너는 어떻게 사용해야합니까? 내 생각에는Xamarin Forms : 프리즘 - 단일 IoC 사용과 관련된 문제?
Container.Resolve<Interface,Implentation>
우리는 IOC의를 해결하고 app.xaml.cs.에 초기화 할 필요가 없습니다 있습니다 그러나 나는 그것을 할 수있는 적절한 방법을 찾을 수 없습니다. 누구든지 나를 도울 수 있습니까?
UPDATE :
페이지 :
<?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>
뷰 모델 :
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.Pro의 Main.cs에서 오류가 발생했습니다 오류 : Foundation.MonoTouchException NSInternalLnconistencyException 이유 : 응용 프로그램 창에 응용 프로그램의 끝에 루트보기 컨트롤러가 있어야합니다.
Visual Studio Extension for Prism 템플릿 팩을 설치하고 그것을 사용하여 –
솔루션을 만듭니다. – TheDeveloper
컨테이너를 사용하여 IMenuList 인터페이스를 클래스로 등록하십시오. –