Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve enforces passed arguments to be used (and fails because of it) #646

Open
cytoph opened this issue Jun 13, 2024 · 5 comments
Open

Comments

@cytoph
Copy link

cytoph commented Jun 13, 2024

I just updated DryIoc from version 5.0.2 to 5.4.0 and an error starts occurring (of which I could not find anything in breaking changes or such). The error occurs on calling container.Resolve(serviceType, [service]). service is, in this case, a service instance that I want to be passed to the serviceType constructor in place of the instance that is registered in the container (that's why I pass it). This worked fine before the update. Now, on version 5.4.0, I get an exception, because the container tries to pass this service instance to every other (undelying) service that is resolved during this call, and not just that, it forces it to be present in every constructor, it seems, which leads to the following exception:

DryIoc.ContainerException: code: Error.UnableToResolveFromRegisteredServices;
message: Unable to resolve MyProject.Shared.Converters.IntegerConverter with passed arguments [INavigationService@0] (IsSingletonOrDependencyOfSingleton, IsWrappedInFunc)
  in MyProject.Shared.Converters.FieldValueConverter: MyProject.Shared.Converters.IConverter {ServiceKey=MyProject.Shared.Converters.FieldValueConverter, DryIoc.IfUnresolved.ReturnDefaultIfNotRegistered} FactoryId=862 with passed arguments [INavigationService@0] (IsSingletonOrDependencyOfSingleton, IsWrappedInFunc, IsDirectlyWrappedInFunc)
  in wrapper Func<MyProject.Shared.Converters.IConverter> RequiredServiceType=MyProject.Shared.Converters.IConverter, ServiceKey=MyProject.Shared.Converters.FieldValueConverter, DryIoc.IfUnresolved.ReturnDefaultIfNotRegistered} WrapperExpressionFactory  FactoryId=885 with passed arguments [INavigationService@0] (IsSingletonOrDependencyOfSingleton, IsWrappedInFunc)
  in wrapper KeyValuePair<Type, Func<MyProject.Shared.Converters.IConverter>> RequiredServiceType=MyProject.Shared.Converters.IConverter, ServiceKey=MyProject.Shared.Converters.FieldValueConverter, DryIoc.IfUnresolved.ReturnDefaultIfNotRegistered} WrapperExpressionFactoryWithSetup  FactoryId=878 with passed arguments [INavigationService@0] (IsSingletonOrDependencyOfSingleton, IsWrappedInFunc)
  in wrapper IEnumerable<KeyValuePair<Type, Func<MyProject.Shared.Converters.IConverter>>> as parameter "factories" ExpressionFactory  FactoryId=875 with passed arguments [INavigationService@0] (IsSingletonOrDependencyOfSingleton, IsWrappedInFunc)
  in Singleton MyProject.Client.Services.ConverterFactory as parameter "converterFactory" FactoryId=872 with passed arguments [INavigationService@0] (IsSingletonOrDependencyOfSingleton, IsWrappedInFunc)
  in MyProject.Client.Services.AdditionalFieldsHelperService as parameter "additionalFieldsHelperService" FactoryId=820 with passed arguments [INavigationService@0] (IsSingletonOrDependencyOfSingleton, IsWrappedInFunc)
  in MyProject.Client.Services.DocumentFactory FactoryId=823 with passed arguments [INavigationService@0] (IsSingletonOrDependencyOfSingleton, IsWrappedInFunc)
  in MyProject.Client.Processes.Sales.SalesDelivery: MyProject.Client.Processes.IProcess {ServiceKey=MyProject.Shared.Enums.Process.SalesDelivery, DryIoc.IfUnresolved.ReturnDefaultIfNotRegistered} FactoryId=826 with passed arguments [INavigationService@0] (IsSingletonOrDependencyOfSingleton, IsWrappedInFunc, IsDirectlyWrappedInFunc)
  in wrapper Func<My.Framework.Maui.Navigation.INavigationService, MyProject.Client.Processes.IProcess> RequiredServiceType=MyProject.Client.Processes.IProcess, ServiceKey=MyProject.Shared.Enums.Process.SalesDelivery, DryIoc.IfUnresolved.ReturnDefaultIfNotRegistered} WrapperExpressionFactoryWithSetup  FactoryId=886 with passed arguments [INavigationService@0] (IsSingletonOrDependencyOfSingleton)
  in wrapper KeyValuePair<MyProject.Shared.Enums.Process, Func<My.Framework.Maui.Navigation.INavigationService, MyProject.Client.Processes.IProcess>> RequiredServiceType=MyProject.Client.Processes.IProcess, ServiceKey=MyProject.Shared.Enums.Process.SalesDelivery, DryIoc.IfUnresolved.ReturnDefaultIfNotRegistered} WrapperExpressionFactoryWithSetup  FactoryId=878 with passed arguments [Constant(My.Framework.Maui.Navigation.Implementations.NavigationService, typeof(My.Framework.Maui.Navigation.Implementations.NavigationService))] (IsSingletonOrDependencyOfSingleton)
  in wrapper IEnumerable<KeyValuePair<MyProject.Shared.Enums.Process, Func<My.Framework.Maui.Navigation.INavigationService, MyProject.Client.Processes.IProcess>>> as parameter "factories" ExpressionFactory  FactoryId=875 with passed arguments [Constant(My.Framework.Maui.Navigation.Implementations.NavigationService, typeof(My.Framework.Maui.Navigation.Implementations.NavigationService))] (IsSingletonOrDependencyOfSingleton)
  in Singleton MyProject.Client.Services.ProcessService as parameter "processService" FactoryId=811 with passed arguments [Constant(My.Framework.Maui.Navigation.Implementations.NavigationService, typeof(My.Framework.Maui.Navigation.Implementations.NavigationService))] (IsSingletonOrDependencyOfSingleton)
  in resolution root MyProject.Client.Views.MainViewModel FactoryId=758 with passed arguments [Constant(My.Framework.Maui.Navigation.Implementations.NavigationService, typeof(My.Framework.Maui.Navigation.Implementations.NavigationService))]
  from container without scope
 with Rules with {TrackingDisposableTransients, SelectLastRegisteredFactory} and without {ThrowOnRegisteringDisposableTransient, VariantGenericTypesInResolvedCollection}
 with FactorySelector=SelectLastRegisteredFactory
 with Made={FactoryMethod=ConstructorWithResolvableArguments}
  with normal and dynamic registrations:
  (MyProject.Shared.Converters.IntegerConverter, {FactoryID=863, ImplType=MyProject.Shared.Converters.IntegerConverter})
   at DryIoc.Throw.It(Int32 error, Object arg0, Object arg1, Object arg2, Object arg3) in /_/src/DryIoc/Container.cs:line 14641
   at DryIoc.Container.TryThrowUnableToResolve(Request request) in /_/src/DryIoc/Container.cs:line 930
   at DryIoc.Container.DryIoc.IContainer.ResolveFactory(Request request) in /_/src/DryIoc/Container.cs:line 912
   at DryIoc.ReflectionFactory.CreateExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 12013
   at DryIoc.Factory.GetExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 10969
   at DryIoc.WrappersSupport.GetFuncOrActionExpressionOrDefault(Request request, Factory serviceFactory) in /_/src/DryIoc/Container.cs:line 5267
   at DryIoc.WrapperExpressionFactory.CreateExpressionWithWrappedFactory(Request request, Factory serviceFactory) in /_/src/DryIoc/Container.cs:line 12534
   at DryIoc.Factory.GetExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 10969
   at DryIoc.WrappersSupport.GetKeyValuePairExpressionOrDefault(Request request, Factory serviceFactory) in /_/src/DryIoc/Container.cs:line 5339
   at DryIoc.WrapperExpressionFactory.CreateExpressionWithWrappedFactory(Request request, Factory serviceFactory) in /_/src/DryIoc/Container.cs:line 12534
   at DryIoc.Factory.GetExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 10969
   at DryIoc.WrappersSupport.GetArrayExpression(Request request) in /_/src/DryIoc/Container.cs:line 5152
   at DryIoc.WrappersSupport.<>c.<BuildSupportedWrappers>b__9_0(Request r) in /_/src/DryIoc/Container.cs:line 4992
   at DryIoc.ExpressionFactory.CreateExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 12482
   at DryIoc.Factory.GetExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 10969
   at DryIoc.ReflectionFactory.CreateExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 12013
   at DryIoc.Factory.GetExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 10969
   at DryIoc.ReflectionFactory.CreateExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 12013
   at DryIoc.Factory.GetExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 10969
   at DryIoc.ReflectionFactory.CreateExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 12013
   at DryIoc.Factory.GetExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 10969
   at DryIoc.ReflectionFactory.CreateExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 12013
   at DryIoc.Factory.GetExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 10969
   at DryIoc.WrappersSupport.GetFuncOrActionExpressionOrDefault(Request request, Factory serviceFactory) in /_/src/DryIoc/Container.cs:line 5267
   at DryIoc.WrapperExpressionFactory.CreateExpressionWithWrappedFactory(Request request, Factory serviceFactory) in /_/src/DryIoc/Container.cs:line 12534
   at DryIoc.Factory.GetExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 10969
   at DryIoc.WrappersSupport.GetKeyValuePairExpressionOrDefault(Request request, Factory serviceFactory) in /_/src/DryIoc/Container.cs:line 5339
   at DryIoc.WrapperExpressionFactory.CreateExpressionWithWrappedFactory(Request request, Factory serviceFactory) in /_/src/DryIoc/Container.cs:line 12534
   at DryIoc.Factory.GetExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 10969
   at DryIoc.WrappersSupport.GetArrayExpression(Request request) in /_/src/DryIoc/Container.cs:line 5152
   at DryIoc.WrappersSupport.<>c.<BuildSupportedWrappers>b__9_0(Request r) in /_/src/DryIoc/Container.cs:line 4992
   at DryIoc.ExpressionFactory.CreateExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 12482
   at DryIoc.Factory.GetExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 10969
   at DryIoc.ReflectionFactory.CreateExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 12013
   at DryIoc.Factory.GetExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 10969
   at DryIoc.ReflectionFactory.CreateExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 12013
   at DryIoc.Factory.GetExpressionOrDefault(Request request) in /_/src/DryIoc/Container.cs:line 10969
   at DryIoc.Container.ResolveAndCacheKeyed(Int32 serviceTypeHash, Type serviceType, Object serviceKey, IfUnresolved ifUnresolved, Object scopeName, Type requiredServiceType, Request preResolveParent, Object[] args) in /_/src/DryIoc/Container.cs:line 538
   at DryIoc.Container.DryIoc.IResolver.Resolve(Type serviceType, Object serviceKey, IfUnresolved ifUnresolved, Type requiredServiceType, Request preResolveParent, Object[] args) in /_/src/DryIoc/Container.cs:line 466
   at DryIoc.Resolver.Resolve(IResolver resolver, Type serviceType, Object[] args, IfUnresolved ifUnresolved, Type requiredServiceType, Object serviceKey) in /_/src/DryIoc/Container.cs:line 8609
   at My.Framework.Maui.Navigation.Implementations.NavigationService.ResolveView(Type viewModelType, INavigation pageNavigation) in C:\Projects\My.Framework.Maui\Navigation\Implementations\NavigationService.cs:line 245
   at My.Framework.Maui.Navigation.Implementations.NavigationService.PushAsync(Type viewModelType, IEnumerable`1 parameters, ModalType modal, Boolean animated) in C:\Projects\My.Framework.Maui\Navigation\Implementations\NavigationService.cs:line 36

I didn't change anything on the containers rules or such. Is there a new rule or parameter that's now set by default, that I must explicitly disable to get this to work again?

@dadhi
Copy link
Owner

dadhi commented Jun 13, 2024

Hi @cytoph
It is too deep of the stack trace. Could you illustrate with the smaller example?

@dadhi
Copy link
Owner

dadhi commented Jun 13, 2024

Also, from your description:

because the container tries to pass this service instance to every other (undelying) service that is resolved during this call, and not just that, it forces it to be present in every constructor

This behavior is intended and supposed to be working in the v5 and v5.4.

But I am not sure how this behavior leads to the specific exception Error.UnableToResolveFromRegisteredServices
So the smaller example is needed.

@cytoph
Copy link
Author

cytoph commented Jun 18, 2024

I tried to reproduce this with a smaller example, but I'm not able to. All I know is when my project references DryIoc.Microsoft.DependencyInjection 6.0.2 (DryIoc.dll 5.0.2) it works, with DryIoc.Microsoft.DependencyInjection 6.2.0 (DryIoc.dll 5.4.0) it doesn't. I'm still working on an example, but I'm not sure, if I'll be able to provide it.

@dadhi
Copy link
Owner

dadhi commented Jun 25, 2024

@cytoph Could you check if the same issue happens for the latest preview 6.0.0-preview-07?

@dadhi
Copy link
Owner

dadhi commented Aug 29, 2024

@cytoph Did you check with DryIoc v6 preview?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants