Core 1.1 : Unable to resolve service for type .. ModelContext

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
jason_m
Posts: 2
Joined: Tue 19 Sep 2017 11:07

Core 1.1 : Unable to resolve service for type .. ModelContext

Post by jason_m » Tue 19 Sep 2017 11:18

Create new ASP.NET Core Web Application Project in VS 2017
Select Web API (options: .NET Core & ASP.NET Core 1.1)
In Package Manager Console:
Install-Package Microsoft.EntityFrameworkCore.Tools -Version 1.1.0
Install-Package Devart.Data.Oracle.EFCore.Design
Scaffold-DbContext "User Id=demo;Password=password;Data Source=XE;" Devart.Data.Oracle.Entity.EFCore -Tables PERSON -outputdir Models

Right-click Controllers-folder
Add --> New Scaffolded Item...
(Select Full Dependencies, if asked)
Select API Controller with actions, using Entity Framework
- Add
- Model Class: Person
- Data Context Class: ModelContext
- Add

To startup.cs Configure-method, add app.UseDeveloperExceptionPage();:
...
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseDeveloperExceptionPage();
...

Press F5 and navigate to api/Persons

--> error :
InvalidOperationException: Unable to resolve service for type 'WebApplication1.Models.ModelContext' while attempting to activate 'WebApplication1.Controllers.PersonsController'.


How to fix this?

jason_m
Posts: 2
Joined: Tue 19 Sep 2017 11:07

Re: Core 1.1 : Unable to resolve service for type .. ModelContext

Post by jason_m » Wed 20 Sep 2017 06:09

Solved: Add:
services.AddDbContext<ModelContext>(options => options.UseOracle(Configuration["ORACLE_CONNECTION_STRING"]));
To ConfigureServices-method in Startup.cs

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: Core 1.1 : Unable to resolve service for type .. ModelContext

Post by Pinturiccio » Fri 22 Sep 2017 12:00

We are glad to hear that the issue is solved. Feel free to contact us if you have any further questions.

Post Reply