question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

asp.net core with jasper, no longer possible to resolve DbContext

See original GitHub issue

I have an asp.net core app, where jasper is registerd as follows:

public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .UseJasper<JasperConfig>()
                .Build();

JasperConfig doesn’t contain any DI registrations. My regular startup.cs though, contains a registration for dbContext and for IMyService.

 public void ConfigureServices(IServiceCollection services)
        {
            string connectionString = "Server=(localdb)\\mssqllocaldb;Database=etc ....;

            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(connectionString));
            services.AddScoped(typeof(IMyService), typeof(MyService));
            services.AddMvc();
        }

Now, I have an mvc controller with following constructor:

public ValuesController(IMessageContext messageContext, IMyService myService, ApplicationDbContext dbContext)

        {
            _messageContext = messageContext;
            _myService = myService;
            _dbContext = dbContext;
        }

The Jasper messageContext and myService are resolved but dbContext is NOT resolved. When I remove the jasper registration (and remove IMessageContext from constructor) everything works fine.

Any idea what i’m doing ‘wrong’? thx

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
jeremydmillercommented, May 30, 2018

Got it.

1reaction
jeremydmillercommented, May 25, 2018

Huh, okay then. I’ll take a look over the weekend. Thanks for the repro steps, that should make this quick.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to resolve service for type ¨Microsoft. ...
I've recently began learning ASP .net core, and wanted to build a library where i have to have a database, login system and...
Read more >
Unable to resolve service for type in .NET 5 with entity ...
Hi I am trying to do a website using .NET 5 with some entity framework 3.1.21. I get this error on my Comments/index...
Read more >
Fix the 'Unable to resolve service for type Microsoft ...
This error means you haven't registered your DbContext as a service in the ConfigureServices section of Startup.cs. This post shows you how.
Read more >
EF Migration Error : Unable to resolve service for type ' ...
The issue occurs because the DbContextOptions is not configured. You can do this by overriding the "OnConfiguring" method. image.
Read more >
ASP.NET Core Multi-tenancy: Data Isolation with Entity ...
The next in my series on building multi-tenant applications with ASP.NET Core, this post looks at how to achieve database isolation with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found