我正在使用 catel 4 预发行版,只是试图将我的用户控件更改为 catel 用户控件,但由于某种原因,catel 无法传递 catel 基本构造函数并抛出此 TypeNotRegisteredException .. 有人可以告诉我我是什么' m 通过锁定调用堆栈而丢失或做错了?
Catel.Core!Catel.IoC.TypeNotRegisteredException.TypeNotRegisteredException(System.Type requestedType = {System.RuntimeType}) Line 22 C#
Catel.Core!Catel.IoC.ServiceLocator.ThrowTypeNotRegisteredException(System.Type type = {System.RuntimeType}) Line 849 + 0x19 bytes C#
Catel.Core!Catel.IoC.ServiceLocator.CreateServiceInstance(Catel.IoC.ServiceLocatorRegistration registration = {System.RuntimeType} => {System.RuntimeType} (Singleton)) Line 805 C#
Catel.Core!Catel.IoC.ServiceLocator.RegisterType.AnonymousMethod__10(Catel.IoC.ServiceLocatorRegistration x = {System.RuntimeType} => {System.RuntimeType} (Singleton)) Line 729 + 0x1c bytes C#
Catel.Core!Catel.IoC.ServiceLocator.ResolveTypeFromKnownContainer(System.Type serviceType = {System.RuntimeType}, object tag = null) Line 775 + 0x23 bytes C#
Catel.Core!Catel.IoC.ServiceLocator.ResolveType(System.Type serviceType = {System.RuntimeType}, object tag = null) Line 444 + 0x13 bytes C#
Catel.Core!Catel.IoC.CatelDependencyResolver.Resolve(System.Type type = {System.RuntimeType}, object tag = null) Line 82 + 0x18 bytes C#
Catel.Core!Catel.IoC.DependencyResolverExtensions.Resolve<Catel.MVVM.IViewModelFactory>(Catel.IoC.IDependencyResolver dependencyResolver = {Catel.IoC.CatelDependencyResolver}, object tag = null) Line 43 + 0x59 bytes C#
Catel.MVVM!Catel.MVVM.Providers.LogicBase.LogicBase() Line 121 + 0x10 bytes C#
[Managed to Native Transition]
Catel.MVVM!Catel.MVVM.Providers.UserControlLogic.UserControlLogic(Catel.MVVM.Views.IView targetView = {MyApp.Views.MainPage}, System.Type viewModelType = null, Catel.MVVM.IViewModel viewModel = null) Line 91 C#
Catel.MVVM!Catel.Windows.Controls.UserControl.UserControl(Catel.MVVM.IViewModel viewModel = null) Line 77 + 0x26 bytes C#
Catel.MVVM!Catel.Windows.Controls.UserControl.UserControl() Line 64 C#
MyApp!MyApp.Views.MainPage.MainPage() Line 23 + 0x9 bytes C#
(我保持调试会话打开,因此我可以提供所需的任何其他详细信息或参数)
提前致谢
ps 如果可以的话,我还有一个问题:我从 nuget 中提取的 catel 4 pre-release beta 的 git 分支名称是什么..(我找不到任何类似于该版本的名称,master 是 3.9 并开发代码似乎与拉出的 pdb 有点不一致..更多关于我设置调试为我工作的信息)
新的
@geert
请求的类型是 Catel.MVVM.IViewModelFactory 。(我似乎无法从中做出任何事情。)回到堆栈中的 CreateServiceInstance 框架
私有对象 CreateServiceInstance(ServiceLocatorRegistration 注册)
{
object instance = TypeFactory.CreateInstance(registration.ImplementingType);//ImplementingType = {MyApp.CustomViewModelFactory}
if (instance == null) //在这种情况下实例为空
{
ThrowTypeNotRegisteredException(registration.DeclaringType);
}
...
如上所述(内联),TypeFactory.CreateInstance 使用 ImplementingType = {MyApp.CustomViewModelFactory} 调用,但返回 null(实例)..
我打电话
serviceLocator.RegisterType<IViewModelFactory, CustomViewModelFactory>();在我的application_startup中,这是我的实现..但我似乎无法从所有这些中做出一些事情,我做错了什么?请帮忙(这可能是一个错误吗?)
public class CustomViewModelFactory : ViewModelFactory
{
private readonly ServiceProviderBase _sp;
CustomViewModelFactory(ITypeFactory typeFactory):base(typeFactory)
{
_sp = ServiceProviderBase.Instance;
}
public override IViewModel CreateViewModel(Type viewModelType, object dataContext)
{
// add here any ViewModel that need some special init params
if (viewModelType == typeof(MySpecialViewModel))
{
// Use custom constructor with dependency injection
return new MySpecialViewModel(_sp.PageConductor, _sp.MySpecialDataService);
}
// Fall back to default behavior
return base.CreateViewModel(viewModelType, dataContext);
}
}
}
ps
我有:LogManager.AddDebugListener(); ( + LogManager.IsDebugEnabled = true;) 但我在输出窗口中看不到任何 catel 日志记录 (vs2012+vs2010)
另一件事..从UserControl“进入” ..进入UserControlLogic:base ..-只是“直接”跳转到那个异常..但是调用堆栈是上面写的(我是否错过了太多睡眠时间%-)