Closed Mubark-p closed 9 months ago
@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. https://github.com/FluentValidation/FluentValidation/issues/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.
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'.)'