Error On Register IN DI
Mubark-p opened this issue · comments
System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Carter.IValidatorLocator Lifetime: Singleton ImplementationType: Carter.DefaultValidatorLocator': Cannot consume scoped service 'System.Collections.Generic.IEnumerable`1[FluentValidation.IValidator]' from singleton 'Carter.IValidatorLocator'.)'
@Mubark-p Test with the new version. You can now define the scope of validators.
Can You explain how? @crodriguesbr Probably because Carter, my FluentValidation is not working. FluentValidation/FluentValidation#2183
carter.ivalidatorlocator lifetime: singleton implementationtype: carter.defaultvalidatorlocator': cannot consume scoped service 'savethekitty.api.databases.interfaces.imaindbcontext' from singleton 'fluentvalidation.ivalidator'.
@koniecdev A service registered as a singleton cannot invoke a service registered as scoped, which is why a way of defining how validators would be registered was implemented in Carter.
services.AddCarter(configurator: cfg => { cfg.WithValidatorLifetime(ServiceLifetime.Scoped); });
I hope it resolves.
It worked @crodriguesbr . Thank You. I kinda wonder why is this not default ngl.
@koniecdev As Carter already registered validators as singletons, we decided to keep them registered by default to avoid code breakage. Still, we left the developer the option to change this.