ASP.NET - Adding a Service to an ASP.NET Core Website [4 of 13]

Play ASP.NET - Adding a Service to an ASP.NET Core Website [4 of 13]

The Discussion

  • User profile image
    David

    This code blows up when I enter it. It has no idea what IWebHostEnvironment is, it's underlined and I can't find any documentation, I have all the using statements you have but nothing's working! :(

  • User profile image
    Niner838598
    I added the "Microsoft.AspNetCore.Hosting" Nuget, still it's showing "IWebHostEnvironment" could not be found. I am using VS2019 community. Is there any work around?
  • User profile image
    freyzhao
    @Niner838598: IWebHostEnviornment only works for ASP.Net 3.0. Make sure you have VS2019 and the solution is targeting ASP.Net 3.0(Last time I checked it does not support VS2017).
  • User profile image
    CopBlaster
    This is really lame because nobody is going to use a static json file. So, when you try to create a service with an entities model the code will be so different that this is totally useless. Microsoft is making the same mistake they made over a decade ago with their ASP.Net tutorials that would always say something like "you could use a database but for the purpose of this demo I will just use some static data" then when someone decides to use a database they have to do a lot of work that the tutorial does not help with, so in an effort to save time they create more time.

    For instance there is no option to create a CRUD service file from the entities model like there is for a CRUD razor page or CRUD controller, so to have a service at all you will have to find a solution yourself.
  • User profile image
    jigglytep
    @CopBlaster:

    I disagree usin a static JSON file is kind of smart...

    When you are dealing with a nosql database all the data is pretty much in JSON.

    When you build a CRUD app you will have an API that is going to query a database and return a JSON response... this is a clever solution that skips setting up a database, creating a driver and setting up a connection string, messing around with dummy SQL queries.
  • User profile image
    Bharati

    Could you please give the GIT HUB URL for this sample please ? I do not find it in the description of the video nor in any comments.

  • User profile image
    Bharati

    Sorry, found it from Tutorial 3

    https://github.com/dotnet-presentations/ContosoCrafts/blob/master/

  • User profile image
    mtaheij
    The 'snippet' in the Gist is not documented here, but you can find the JsonFileProductService class here:
    https://github.com/dotnet-presentations/ContosoCrafts/blob/master/src/Services/JsonFileProductService.cs

Add Your 2 Cents