@@ -21,7 +21,7 @@ public static IViewLocator Current {
2121 }
2222 }
2323
24- class DefaultViewLocator : IViewLocator
24+ class DefaultViewLocator : IViewLocator , IEnableLogger
2525 {
2626 public Func < string , string > ViewModelToViewFunc { get ; set ; }
2727
@@ -56,21 +56,29 @@ public IViewFor ResolveView<T>(T viewModel, string contract = null)
5656
5757 // IFooBarView that implements IViewFor (or custom ViewModelToViewFunc)
5858 var typeToFind = ViewModelToViewFunc ( viewModel . GetType ( ) . AssemblyQualifiedName ) ;
59- try {
60- var type = Reflection . ReallyFindType ( typeToFind , false ) ;
59+
60+ var ret = attemptToResolveView ( Reflection . ReallyFindType ( typeToFind , false ) , contract ) ;
61+ if ( ret != null ) return ret ;
6162
62- if ( type != null ) {
63- var ret = RxApp . DependencyResolver . GetService ( type , contract ) as IViewFor ;
64- if ( ret != null ) return ret ;
65- }
63+ // IViewFor<FooBarViewModel> (the original behavior in RxUI 3.1)
64+ var viewType = typeof ( IViewFor < > ) ;
65+ return attemptToResolveView ( viewType . MakeGenericType ( viewModel . GetType ( ) ) , contract ) ;
66+ }
67+
68+ IViewFor attemptToResolveView ( Type type , string contract )
69+ {
70+ if ( type == null ) return null ;
71+
72+ var ret = default ( IViewFor ) ;
73+
74+ try {
75+ ret = ( IViewFor ) RxApp . DependencyResolver . GetService ( type , contract ) ;
6676 } catch ( Exception ex ) {
67- LogHost . Default . DebugException ( "Couldn't instantiate " + typeToFind , ex ) ;
77+ this . Log ( ) . ErrorException ( "Failed to instantiate view: " + type . FullName , ex ) ;
78+ throw ;
6879 }
6980
70- var viewType = typeof ( IViewFor < > ) ;
71-
72- // IViewFor<FooBarViewModel> (the original behavior in RxUI 3.1)
73- return ( IViewFor ) RxApp . DependencyResolver . GetService ( viewType . MakeGenericType ( viewModel . GetType ( ) ) , contract ) ;
81+ return ret ;
7482 }
7583
7684 static string interfaceifyTypeName ( string typeName )
0 commit comments