13 Replies
Inject it
Add it as one of the parameters of your lambda
in minimal api every service is injected via parameters, this includes ur db context as well.
eg, u could also inject an
ILogger
by adding one as parametercould someone provide a code snippet ?
all i get is:
this is my data context:
do I have to change something?
No, looks good to me
How does your
MapPost
look with the context injected?looks like this:
Try adding
[FromServices]
attribute to the parameter, then
Also, just to make sure, your dbcontext is registered in the services?System.InvalidOperationException: No service for type 'GetOut.Data.DataContext' has been registered.
how to register it ?
builder.Services.AddDbContext<DataContext>();
OK, I have done it. No database provider has been configured for this DbContext.
Override the
OnConfiguring()
method in the dbcontext
And configure what provider you want to useWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.