René's URL Explorer Experiment


Title: Can't inject IRepository(but RepositoryFactory and ConfigurationBasedRepository works fine) · Issue #235 · SharpRepository/SharpRepository · GitHub

Open Graph Title: Can't inject IRepository(but RepositoryFactory and ConfigurationBasedRepository works fine) · Issue #235 · SharpRepository/SharpRepository

X Title: Can't inject IRepository(but RepositoryFactory and ConfigurationBasedRepository works fine) · Issue #235 · SharpRepository/SharpRepository

Description: Hi, My first post here and I just discovered SharpRepository and trying to use it in our projects. Sorry for the lengthy post, I am trying to provide as much details as possible on all the information I've gathered. I'm using .Net Core 2...

Open Graph Description: Hi, My first post here and I just discovered SharpRepository and trying to use it in our projects. Sorry for the lengthy post, I am trying to provide as much details as possible on all the informat...

X Description: Hi, My first post here and I just discovered SharpRepository and trying to use it in our projects. Sorry for the lengthy post, I am trying to provide as much details as possible on all the informat...

Opengraph URL: https://github.com/SharpRepository/SharpRepository/issues/235

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Can't inject IRepository\u003cXXXXX, int\u003e(but RepositoryFactory and ConfigurationBasedRepository works fine)","articleBody":"Hi,\r\n\r\nMy first post here and I just discovered SharpRepository and trying to use it in our projects.\r\n\r\nSorry for the lengthy post, I am trying to provide as much details as possible on all the information I've gathered.\r\n\r\nI'm using .Net Core 2.2 and I have followed the example of SharpRepository.Samples.CoreMvc. I have changed the .Net version of that code and I made it use 2.2 (it is using 2.1 when download from GitHub). In that project, using .Net Core 2.2 it is possible to inject properly ConfigurationBasedRepository  and IRepository\u003cXXXX, int\u003e.\r\n\r\n My issue is that I'm having some problems to inject into my services a repository of type \"IRepository\u003cAppUser, int\u003e\". However a ConfigurationBasedRepository works fine.\r\n\r\nIf I inject a UserRepository, the injector works well:\r\n```\r\n\tpublic class UserRepository : ConfigurationBasedRepository\u003cAppUser, int\u003e {\r\n\tpublic UserRepository(ISharpRepositoryConfiguration configuration, string repositoryName = null) : base(configuration, repositoryName){}\r\n\t}\r\n\tpublic UserService(ApplicationDbContext context, ILogger\u003cUserService\u003e logger){\r\n\t           _userRepository = userRepository;\r\n\t}\r\n```\r\n\r\nAlso, when I call directly the RepositoryFactory, I'm able to build a repository of the type I'm interested. The code below works fine as well:\r\n\r\n```\r\npublic UserService(ApplicationDbContext context, ILogger\u003cUserService\u003e logger)\r\n{\r\n    _context = context;\r\n    _logger = logger;\r\n\r\n    var dbContext = _context;\r\n    var config = new SharpRepositoryConfiguration();\r\n    var coreRepoconfig = new EfCoreRepositoryConfiguration(\"default\", dbContext);\r\n    coreRepoconfig.Attributes.Add(\"dbContextType\", \"Base.DataAccessLayer.Identity.ApplicationDbContext, Base.DataAccessLayer\");\r\n    config.AddRepository(coreRepoconfig);\r\n    var repos = RepositoryFactory.GetInstance\u003cAppUser, int\u003e(config);\r\n}\r\n```\r\n\r\nHOWEVER, if I want to inject the Repository, it crashes and it throws an exception:\r\n\r\n```\r\nprivate IRepository\u003cAppUser, int\u003e _userRepository;\r\n\r\n    public UserService(ApplicationDbContext context, ILogger\u003cUserService\u003e logger, IRepository\u003cAppUser, int\u003e userRepository)\r\n    {\r\n        _userRepository = userRepository;\r\n        _context = context;\r\n        _logger = logger;\r\n    }\r\n```\r\n\r\n\r\n    \r\n```\r\n2019-05-31 15:46:57.500 +02:00 [{ IpAddress: \"0.0.0.1\" }] [Error] [] Connection id \"\"0HLN5PPF1NBND\"\", Request id \"\"0HLN5PPF1NBND:00000003\"\": An unhandled exception was thrown by the application.\r\nSystem.InvalidOperationException: Unable to resolve service for type 'SharpRepository.Repository.IRepository`2[Base.DataAccessLayer.Models.AppUser,System.Int32]' while attempting to activate 'Base.BusinessLayer.UserService.UserService'.\r\n   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)\r\n   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(Type serviceType, Type implementationType, CallSiteChain callSiteChain)\r\n   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain)\r\n   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type serviceType, CallSiteChain callSiteChain)\r\n   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain)\r\n   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.CreateServiceAccessor(Type serviceType)\r\n   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)\r\n   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)\r\n   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)\r\n   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)\r\n   at lambda_method(Closure , IServiceProvider , Object[] )\r\n   at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.\u003c\u003ec__DisplayClass4_0.\u003cCreateActivator\u003eb__0(ControllerContext controllerContext)\r\n   at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.\u003c\u003ec__DisplayClass5_0.\u003cCreateControllerFactory\u003eg__CreateController|0(ControllerContext controllerContext)\r\n   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State\u0026 next, Scope\u0026 scope, Object\u0026 state, Boolean\u0026 isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()\r\n   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()\r\n   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)\r\n   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State\u0026 next, Scope\u0026 scope, Object\u0026 state, Boolean\u0026 isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()\r\n   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()\r\n   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)\r\n   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)\r\n   at Base.WebServices.Middlewares.JwtTokenMiddleware.Invoke(HttpContext context) in E:\\SampleCode\\Base.Services\\Middlewares\\JwtTokenMiddleware.cs:line 41\r\n   at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.InvokeCore(HttpContext context)\r\n   at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext)\r\n   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)\r\n```\r\n\r\n   \r\n\r\n\r\n\r\nThis is the code in my startup.cs:\r\n```\r\n      public void ConfigureServices(IServiceCollection services)\r\n        {\r\n            services.AddMvc();\r\n\r\n            // Add framework services.\r\n            services.AddDbContext\u003cApplicationDbContext\u003e(options =\u003e\r\n                options.UseSqlServer(Configuration[\"ConnectionString\"],\r\n                    sqlOptions =\u003e\r\n                    {\r\n                        sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);\r\n                        //Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency \r\n                        sqlOptions.EnableRetryOnFailure(15, TimeSpan.FromSeconds(30), null);\r\n                        sqlOptions.MigrationsAssembly(\"Base.DataAccessLayer\");\r\n                    }), ServiceLifetime.Transient);\r\n\r\n            services.AddIdentity\u003cAppUser, AppRole\u003e()\r\n                .AddEntityFrameworkStores\u003cApplicationDbContext\u003e().AddDefaultTokenProviders();\r\n\r\n            // configure DI for application services\r\n            services.AddScoped\u003cIUserService, UserService\u003e();\r\n\r\n            services.AddSingleton\u003cIHttpContextAccessor, HttpContextAccessor\u003e();\r\n\r\n\r\n            services.AddTransient\u003cUserRepository\u003e(\r\n            r =\u003e new UserRepository(\r\n            \tRepositoryFactory.BuildSharpRepositoryConfiguation(Configuration.GetSection(\"sharpRepository\")), \"efCore\"\r\n            ));\r\n\r\n            // Adding Sharp Repository\r\n            services.UseSharpRepository(Configuration.GetSection(\"sharpRepository\"), \"efCore\"); // for Ef Core\r\n\r\n            }\r\n```\r\n\r\nAnd finally, this is my appsettings.json:\r\n\r\n```\r\n  \"sharpRepository\": {\r\n    \"repositories\": {\r\n      \"default\": \"efCore\",\r\n      \"efCore\": {\r\n        \"factory\": \"SharpRepository.EfCoreRepository.EfCoreConfigRepositoryFactory, SharpRepository.EfCoreRepository\",\r\n        \"dbContextType\": \"Base.DataAccessLayer.Identity.ApplicationDbContext, Base.DataAccessLayer\",\r\n        \"cachingStrategy\": \"none\",\r\n        \"cachingProvider\": \"noCachingProvider\"\r\n      }\r\n    },\r\n    \"cachingProviders\": {\r\n      \"default\": \"inMemoryProvider\",\r\n      \"inMemoryProvider\": {\r\n        \"factory\": \"SharpRepository.Repository.Caching.InMemoryConfigCachingProviderFactory, SharpRepository.Repository\"\r\n      },\r\n      \"noCachingProvider\": {\r\n        \"factory\": \"SharpRepository.Repository.Caching.NoCachingConfigCachingProviderFactory, SharpRepository.Repository\"\r\n      }\r\n    },\r\n    \"cachingStrategies\": {\r\n      \"default\": \"standard\",\r\n      \"standard\": {\r\n        \"factory\": \"SharpRepository.Repository.Caching.StandardConfigCachingStrategyFactory, SharpRepository.Repository\",\r\n        \"generational\": \"true\",\r\n        \"writeThrough\": \"false\"\r\n      },\r\n      \"timeout\": {\r\n        \"factory\": \"SharpRepository.Repository.Caching.TimeoutConfigCachingStrategyFactory, SharpRepository.Repository\",\r\n        \"timeout\": \"200\"\r\n      },\r\n      \"none\": {\r\n        \"factory\": \"SharpRepository.Repository.Caching.NoCachingConfigCachingStrategyFactory, SharpRepository.Repository\"\r\n      }\r\n    }\r\n  }\r\n```\r\n\r\n  Any advice on how to debug/fix this issue?\r\n\r\n  Thanks,\r\n\r\n  Juan","author":{"url":"https://github.com/jhuerta","@type":"Person","name":"jhuerta"},"datePublished":"2019-05-31T14:09:58.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/235/SharpRepository/issues/235"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f1d40f24-2760-0d4e-cc0c-cb682e2ddc25
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAE44:1494FD:39E1658:4C52C66:697468A7
html-safe-nonce70a45484763e02151273fdbd72ac9d6bfd1040bbeed96991d0afa64f7b81b76c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTQ0OjE0OTRGRDozOUUxNjU4OjRDNTJDNjY6Njk3NDY4QTciLCJ2aXNpdG9yX2lkIjoiNjM0NzYzOTE4NjIyNzc1MTA3OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac3fc9513d45c7de421150ab13712a82ef3bbf6f0abf1e02b095f8f1c3992131b8
hovercard-subject-tagissue:450818180
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/SharpRepository/SharpRepository/235/issue_layout
twitter:imagehttps://opengraph.githubassets.com/03e067723d869bf0a8ad9b2db27ffb479bba919311001726b4d1cd300f10e6e0/SharpRepository/SharpRepository/issues/235
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/03e067723d869bf0a8ad9b2db27ffb479bba919311001726b4d1cd300f10e6e0/SharpRepository/SharpRepository/issues/235
og:image:altHi, My first post here and I just discovered SharpRepository and trying to use it in our projects. Sorry for the lengthy post, I am trying to provide as much details as possible on all the informat...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejhuerta
hostnamegithub.com
expected-hostnamegithub.com
Nonee0b95d743b7672c9ac0e1032d5f117950182dc164a83434a7db86510e8f0b37c
turbo-cache-controlno-preview
go-importgithub.com/SharpRepository/SharpRepository git https://github.com/SharpRepository/SharpRepository.git
octolytics-dimension-user_id1801360
octolytics-dimension-user_loginSharpRepository
octolytics-dimension-repository_id4514047
octolytics-dimension-repository_nwoSharpRepository/SharpRepository
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id4514047
octolytics-dimension-repository_network_root_nwoSharpRepository/SharpRepository
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release56fe7e2e8de6e57740bca50402351ea656f7a4bf
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/SharpRepository/SharpRepository/issues/235#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FSharpRepository%2FSharpRepository%2Fissues%2F235
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FSharpRepository%2FSharpRepository%2Fissues%2F235
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=SharpRepository%2FSharpRepository
Reloadhttps://github.com/SharpRepository/SharpRepository/issues/235
Reloadhttps://github.com/SharpRepository/SharpRepository/issues/235
Reloadhttps://github.com/SharpRepository/SharpRepository/issues/235
SharpRepository https://github.com/SharpRepository
SharpRepositoryhttps://github.com/SharpRepository/SharpRepository
Notifications https://github.com/login?return_to=%2FSharpRepository%2FSharpRepository
Fork 165 https://github.com/login?return_to=%2FSharpRepository%2FSharpRepository
Star 658 https://github.com/login?return_to=%2FSharpRepository%2FSharpRepository
Code https://github.com/SharpRepository/SharpRepository
Issues 28 https://github.com/SharpRepository/SharpRepository/issues
Pull requests 10 https://github.com/SharpRepository/SharpRepository/pulls
Actions https://github.com/SharpRepository/SharpRepository/actions
Projects 0 https://github.com/SharpRepository/SharpRepository/projects
Wiki https://github.com/SharpRepository/SharpRepository/wiki
Security 0 https://github.com/SharpRepository/SharpRepository/security
Insights https://github.com/SharpRepository/SharpRepository/pulse
Code https://github.com/SharpRepository/SharpRepository
Issues https://github.com/SharpRepository/SharpRepository/issues
Pull requests https://github.com/SharpRepository/SharpRepository/pulls
Actions https://github.com/SharpRepository/SharpRepository/actions
Projects https://github.com/SharpRepository/SharpRepository/projects
Wiki https://github.com/SharpRepository/SharpRepository/wiki
Security https://github.com/SharpRepository/SharpRepository/security
Insights https://github.com/SharpRepository/SharpRepository/pulse
New issuehttps://github.com/login?return_to=https://github.com/SharpRepository/SharpRepository/issues/235
New issuehttps://github.com/login?return_to=https://github.com/SharpRepository/SharpRepository/issues/235
Can't inject IRepository(but RepositoryFactory and ConfigurationBasedRepository works fine)https://github.com/SharpRepository/SharpRepository/issues/235#top
helphttps://github.com/SharpRepository/SharpRepository/issues?q=state%3Aopen%20label%3A%22help%22
https://github.com/jhuerta
https://github.com/jhuerta
jhuertahttps://github.com/jhuerta
on May 31, 2019https://github.com/SharpRepository/SharpRepository/issues/235#issue-450818180
helphttps://github.com/SharpRepository/SharpRepository/issues?q=state%3Aopen%20label%3A%22help%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.