Bean0341 Bean0341 - 26 days ago 14
C# Question

Asp.net api dependency injection location

I am following a tutorial on asp.net web api and mongodb here and on step 4 it talks about dependency injection and adding it to the start.cs in the

ConfigureServices()
method, however this doesnt seem to exist anymore. My web api templates startup.cs looks something like this...

public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}


So my question is where do I inject my DataAccess class to my web api project as a service? Thanks in advance.

As requested here is my api structure

enter image description here

under LGR.API is the auto generated folders and classes created by visual studios and starting a LGR.Datamodel is my custom class with my api stuff. Really new here... not sure if this correct at all. Feel free to critique with best practices as necessary

Answer

It looks like you've created an ASP.NET application, and your tutorial is for ASP.NET Core. Recreate your project and pick the "ASP.NET Core Web Application" template.

Comments