0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Prism コードサンプル学習:09-ChangeConvention

Posted at

Prism コードサンプル学習:09-ChangeConvention

はじめに

以下の記事の続きです。
https://qiita.com/mngreen/items/749a57635cffbb146646

09-ChangeConvention

本サンプルでは、Viewの型からViewModelを取得する際の解消方法を変更しています。
デフォルトの規則ではViewModelはViewModelパッケージ以下に格納されなければ型解消できないのですが、本サンプルでは、Viewパッケージ以下に格納されているにもかかわらずViewModelが生成されています。

    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        ...

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

            ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
            {
                var viewName = viewType.FullName;
                var viewAssemblyName = viewType.GetTypeInfo().Assembly.FullName;
                var viewModelName = $"{viewName}ViewModel, {viewAssemblyName}";
                return Type.GetType(viewModelName);
            });
        }
    }

おわりに

今回はViewModelLocatorの型の解消の変更方法について学習できました。
基本的に自前で変更したいというモチベーションがなければ利用しないかもしれませんが、カスタマイズ性を持たせている点は設計として優れているように感じました。
次回、10-ChangeConventionについて見ていこうと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?