Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Exception when using AddDbConnectionFactoryWithCtx #16

Open
rlgordey opened this issue Aug 15, 2021 · 0 comments
Open

Exception when using AddDbConnectionFactoryWithCtx #16

rlgordey opened this issue Aug 15, 2021 · 0 comments

Comments

@rlgordey
Copy link

This works:

            //Dapper + Logging
            services.AddDbConnectionFactory(
                prv => new SqlConnection(Configuration.GetConnectionString("Database")),
                options => options
                    .WithLogLevel(LogLevel.Debug)
                    .WithSensitiveDataLogging() //to show values of the query parameters
                    .WithConnectionProjector(c => new { c.DataSource, c.Database })
                , ServiceLifetime.Scoped);

This gives an Exception:

//Include extra context into log messages
            services.AddDbConnectionFactoryWithCtx<LoggingContext>(
                prv => new SqlConnection(Configuration.GetConnectionString("Database")),
                options => options
                    .WithLogLevel(LogLevel.Debug)
                    .WithSensitiveDataLogging() //show values of the query parameters
                    .WithConnectionProjector(c => new { c.DataSource, c.Database })
                , ServiceLifetime.Scoped);

System.AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: EcommerceWebAPI.Services.Interfaces.IItemService Lifetime: Scoped ImplementationType: EcommerceWebAPI.Services.ItemService': Unable to resolve service for type 'Dapper.Logging.IDbConnectionFactory' while attempting to activate 'DataAccessLayer.DapperFunctions'.) (Error while validating the service descriptor 'ServiceType: DataAccessLayer.DapperFunctions Lifetime: Scoped ImplementationType: DataAccessLayer.DapperFunctions': Unable to resolve service for type 'Dapper.Logging.IDbConnectionFactory' while attempting to activate 'DataAccessLayer.DapperFunctions'.)

---> System.InvalidOperationException: Error while validating the service descriptor 'ServiceType: EcommerceWebAPI.Services.Interfaces.IItemService Lifetime: Scoped ImplementationType: EcommerceWebAPI.Services.ItemService': Unable to resolve service for type 'Dapper.Logging.IDbConnectionFactory' while attempting to activate 'DataAccessLayer.DapperFunctions'.

---> System.InvalidOperationException: Unable to resolve service for type 'Dapper.Logging.IDbConnectionFactory' while attempting to activate 'DataAccessLayer.DapperFunctions'.

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, Type serviceType, Type implementationType, CallSiteChain callSiteChain)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain, Int32 slot)

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

No branches or pull requests

1 participant