我希望能够使用我的 IoC 容器注入依赖项而不会遇到TinyIoC.TinyIoCResolutionException
异常。
我的 Xamarin Android 应用程序正在使用 TinyIoC 注入依赖项。在应用程序启动时(在其他任何事情发生之前),所有依赖项都注册container
为:
container.Register<IExampleService, ExampleService>();
然后我在活动方法中注册后解决依赖关系onCreate()
,如下所示:
container.Resolve<IExampleService>();
现在一些依赖关系得到了很好的解决,但是其他的则抛出:
TinyIoC.TinyIoCResolutionException
Message = Unable to resolve type: ExamplePackage.ExampleService
Source = Common.Shared.TinyIoC
StackTrace:
at TinyIoC.TinyIoCContainer.ConstructType(System.Type requestedType, System.Type implementationType, System.Reflection.ConstructorInfo constructor, TinyIoC.NamedParameterOverloads parameters, TinyIoC.ResolveOptions options) [0x000c4] in <e0fa358c835b42dcacf38a6ad3cc70cc>:0
at TinyIoC.TinyIoCContainer.ConstructType(System.Type requestedType, System.Type implementationType, System.Reflection.ConstructorInfo constructor, TinyIoC.ResolveOptions options) [0x00009] in <e0fa358c835b42dcacf38a6ad3cc70cc>:0
at TinyIoC.TinyIoCContainer+SingletonFactory.GetObject (System.Type requestedType, TinyIoC.TinyIoCContainer container, TinyIoC.NamedParameterOverloads parameters, TinyIoC.ResolveOptions options)[0x0003b] in <e0fa358c835b42dcacf38a6ad3cc70cc>:0
at TinyIoC.TinyIoCContainer.ResolveInternal (TinyIoC.TinyIoCContainer+TypeRegistration registration, TinyIoC.NamedParameterOverloads parameters, TinyIoC.ResolveOptions options) [0x00027] in <e0fa358c835b42dcacf38a6ad3cc70cc>:0
at TinyIoC.TinyIoCContainer.Resolve(System.Type resolveType) [0x00011] in <e0fa358c835b42dcacf38a6ad3cc70cc>:0
at TinyIoC.TinyIoCContainer.Resolve[ResolveType] ()[0x00000] in <e0fa358c835b42dcacf38a6ad3cc70cc>:0
at Common.Shared.IoC.Tiny.Tiny.Resolve[ResolveType] ()[0x00005] in <8ff607064979404aaa60061c0b7e19eb>:0
at Android.App.Activity.n_OnResume (System.IntPtr jnienv, System.IntPtr native__this)[0x00009] in <4a189ea3b82b48a089ac9002b2abc206>:0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.8(intptr, intptr)
我最近将我的更新Target API
到 28,之前是 21。我不确定这是否是一个因素。