asp.net core with jasper, no longer possible to resolve DbContext
See original GitHub issueI 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:
- Created 5 years ago
- Comments:8 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Got it.
Huh, okay then. I’ll take a look over the weekend. Thanks for the repro steps, that should make this quick.