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

Exception when using AddDbConnectionFactoryWithCtx #16

@rlgordey

Description

@rlgordey

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions