Skip to content

Commit

Permalink
fixed resolver error
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Hindrikes committed Dec 28, 2020
1 parent 0323e3e commit b738822
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
15 changes: 3 additions & 12 deletions src/TinyMvvm.Forms/ViewBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ internal virtual void CreateViewModel()
}
}



public abstract class ViewBase<T> : ViewBase where T:IViewModelBase?
{
public T? ViewModel
Expand All @@ -183,21 +181,18 @@ public T? ViewModel

return default(T);
}
}


}

internal override void CreateViewModel()
{
if (Resolver.IsEnabled)
{
BindingContext = Resolver.Resolve<T>();
BindingContext = Resolver.Resolve(typeof(T));
}
else
{
BindingContext = Activator.CreateInstance(typeof(T));
}

}
}

public ViewBase(bool isShellView)
Expand All @@ -221,18 +216,14 @@ public ViewBase()
}
}


protected override void OnAppearing()
{


if(ViewModel == null && !CreatedByTinyMvvm)
{
CreateViewModel();
}

base.OnAppearing();

}

protected override void OnDisappearing()
Expand Down
4 changes: 2 additions & 2 deletions src/TinyMvvm/IoC/Resolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static bool IsEnabled
}
}

public static T Resolve<T>()
public static T Resolve<T>() where T:class
{
if(_resolver is null)
{
Expand All @@ -31,7 +31,7 @@ public static T Resolve<T>()
return _resolver.Resolve<T>();
}

public static T Resolve<T>(string key)
public static T Resolve<T>(string key) where T : class
{
if (_resolver is null)
{
Expand Down

0 comments on commit b738822

Please sign in to comment.