Skip to content

Doesn't work without entity framework #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bugproof opened this issue Apr 19, 2018 · 2 comments
Closed

Doesn't work without entity framework #261

bugproof opened this issue Apr 19, 2018 · 2 comments
Labels

Comments

@bugproof
Copy link

bugproof commented Apr 19, 2018

No enity framework example itself has dependency on ef

https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/master/src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj

I did everything and without passing DbContext, it won't work.

Unable to resolve service for type 'JsonApiDotNetCore.Data.IDbContextResolver' while attempting to activate 'JsonApiDotNetCore.Data.DefaultEntityRepository`...

It seems like DbContext is required no matter if I use it

@jaredcnance
Copy link
Contributor

jaredcnance commented Apr 19, 2018

Yeah, to be clear, at the current time, you can’t build a JADNC app without taking EF as a dependency. However, you are not required to use it. Since the main project depends on EF directly, everything gets EF as a transitive dependency. This is changing soon. I have one bug that is being addressed by #254, then EF will be extracted into a separate package that the main project will depend on. Then, around v3, to use EF you will have to install JsonApiDotNetCore.EntityFramework on top of it.

Now, back to your question, the error message states that it is trying to resolve the DefaultEntityRepository. If you’re not using EF as your data store, then it shouldn’t be trying to resolve that type. Can you post your controller, service layer (if applicable) and show me where you registered your dependencies on the IoC container?

Now all that said, the example contains this, which should be unnecessary. If it’s actually required, then it’s a bug.

var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>();
optionsBuilder.UseNpgsql(Configuration.GetValue<string>("Data:DefaultConnection"));
services.AddSingleton<IConfiguration>(Configuration);
services.AddSingleton<DbContextOptions<AppDbContext>>(optionsBuilder.Options);
services.AddScoped<AppDbContext>();

@jaredcnance
Copy link
Contributor

jaredcnance commented Jun 6, 2018

Closing, discussion moved to #292. Feel free to reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants