F
Farslayer
Guest
I'm new to C#'s entity framework and a core framework API. Specifically, I think my problem lies with my not understanding DI. I'm getting this error when trying to hit the route that I've defined in my controller:
System.InvalidOperationException: 'Unable to find the required services. Please add all the required services by calling 'IServiceCollection.AddMvc' inside the call to 'ConfigureServices(...)' in the application startup code.'
It seems to start here at the app.UseMvc() call:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
}
This error is showing up in my startup.cs file. Here is the ConfigureServices code block:
public void ConfigureServices(IServiceCollection services)
{
var connectionString = "Server=172.22.20.103;Database=CMDB;User Id=username;Password=password;";
services.AddDbContext<VirtualMachineContext>(options => options.UseSqlServer(connectionString));
services.AddDbContext<ServiceDeskChangeOrderContext>(options => options.UseSqlServer(connectionString));
services.AddDbContext<VirtualMachineSizeContext>(options => options.UseSqlServer(connectionString));
}
Have I done something wrong or is my problem elsewhere in the code?
Continue reading...
System.InvalidOperationException: 'Unable to find the required services. Please add all the required services by calling 'IServiceCollection.AddMvc' inside the call to 'ConfigureServices(...)' in the application startup code.'
It seems to start here at the app.UseMvc() call:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
}
This error is showing up in my startup.cs file. Here is the ConfigureServices code block:
public void ConfigureServices(IServiceCollection services)
{
var connectionString = "Server=172.22.20.103;Database=CMDB;User Id=username;Password=password;";
services.AddDbContext<VirtualMachineContext>(options => options.UseSqlServer(connectionString));
services.AddDbContext<ServiceDeskChangeOrderContext>(options => options.UseSqlServer(connectionString));
services.AddDbContext<VirtualMachineSizeContext>(options => options.UseSqlServer(connectionString));
}
Have I done something wrong or is my problem elsewhere in the code?
Continue reading...