Git Product home page Git Product logo

aspnetcorevideo's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

aspnetcorevideo's Issues

Minor typo on page 80

Just want to report a minor typo on page 80 of Core 1.1 book.

It says:

Preparing the **Crate** View for Validation 

instead of:

Preparing the **Create** View for Validation 

pg. 49, Implementing ContentResult

I'm wondering why this is not working. It looks exactly like in the book and also your github example. I'm using Microsoft.AspNetCore.Mvc;

`
using Microsoft.AspNetCore.Mvc;
namespace ASPNetCoreVideo.Controllers
{
// attribute routing for MVC
[Route("company/[controller]/[action]")]
public class EmployeeController : Controller // error here....
{
public ContentResult Name( )
{
return Content("John Doe"); // error here....
}

  public string Country( )
  {
    return "United States";
  }

  public string JobTitle( )
  {
    return "Web Developer";
  }

  public string Index( )
  {
    return "Hello from EmployeeController() class";
  }      
}

}
`

Error message is

Error | CS0246 | The type or namespace name 'Controller' could not be found (are you missing a using directive or an assembly reference?)

Error | CS0103 | The name 'Content' does not exist in the current context

-- Now, I can get rid of the errors by using System.Web.Mvc but the program doesn't work and the url /company/employee/name does not work and give the correct result. (just an empty page)

/company/employee/country also doesn't work.
but /employee/country works.

So it seems the [Route] is being ignored if I use using System.Web.Mvc
But that's the only way I can get rid of the error messages.

add-migration FAILS, also running the application produces error

I bought the book and am working though it page by page but I am currently stuck in page 94. When I add the migration I get an error shown below.

Unable to create an object of type 'VideoDbContext'. Add an implementation of 'IDesignTimeDbContextFactory' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.

I also tried running the code downloaded from github and I get the following error from the browser.

An unhandled exception occurred while processing the request.
ArgumentNullException: Value cannot be null.
Parameter name: connectionString

Any assistance is much appreciated. Thank you.

John

Wrong code on page 21/22 above the image.

A copy/paste error has found it's way into the book on page 21 (22 in paperback).
A new version of the book will uploaded soon.

The code:

public class HardCodedMessageService : IMessageService
{
    public string GetMessage()
    {
        return "Hardcoded message from a service.";
    }
}

Should be:
The complete code for the ConfigureServices method:

public void ConfigureServices(IServiceCollection services)
{
    services.AddSingleton<IMessageService, HardcodedMessageService>();
}

The complete code for the Configure method:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IMessageService msg)
{
    loggerFactory.AddConsole();

    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.Run(async (context) =>
    {
        await context.Response.WriteAsync(msg.GetMessage());
    });
}

Wrong text no page 15/16 (paperback)

The text:

The Configure method is where you set up the application’s inversion of control container, which will be covered more in the second part of this book.
The second method in the Startup class is ConfigureServices, which is used to configure the application services.

Should be:

In the Configure method, you setup the HTTP request pipeline (the middleware) that is called when the application starts. In the second part of this book, you will add an object-to-object mapper called AutoMapper to this method. AutoMapper transforms objects from one type to another.
The ConfigureServices method is where you set up the services, such as MVC. You can also register your own services and make them ready for DI, for instance the services that you implement using the IMessageService interface at the beginning of the book.

WORKAROUND: For Microsoft Bug when adding NuGet packages

Follow the instructions below if you get the following (or similar) error:

Package 'Microsoft.Extensions.SecretManager.Tools 1.0.1' has a package type 'DotnetCliTool' that is not supported by project 'ASPNetCoreVideo'.

  1. Add the the NuGet packages manually in the .csproj file
  2. Save the .csproj file.
  3. Restart Visual Studio

READ THIS: If you are using the ASP.NET Web Application (.NET Core) template

Changes when using the ASP.NET Core Web Application (.NET Core) template with the Empty project template.

.NET Core repository: https://github.com/csharpschool/AspNetCoreVideoCore

CHAPTER 3
Implement Routing

Substitute existing text in the section with the following

  1. Open the Startup class and locate the Configure method.
  2. Replace the UseMvcWithDefaultRoute method with the UseMvc method and pass in the name of the method to call; let’s call it ConfigureRoutes.
    app.UseMvc();
  3. Locate the UseMvc method in the Configure method and comment it out.
  4. Add a new call to the UseMvc method and add a Lambda expression with the default route template.
    app.UseMvc(routes =>
    {
    routes.MapRoute(
    name: "default",
    template: "{controller=Home}/{action=Index}/{id?}");
    });
  5. Save the file and refresh the application in the browser. As you can see, the Index action was reached with the explicit URL /home/index.
  6. Now change to a URL without the action’s name, and only the controller’s name (/Home). You should still get the message from the action method, because you specified the Index action method as the default action in the routing template.
  7. Now call the root URL. A root URL is a URL with only the localhost and the port specified (http://localhost:xxxxx). This should also call the Index action because both Home and Index are declared as default values for the controller and the action in the routing template.

CHAPTER 7
Adding the HTTP POST Login Action

  • Add a new step between step 2 and 3:
  1. The first thing to do in any HTTP POST action is to check if the model state is valid; if it’s not, then the view should be re-rendered.
    if (!ModelState.IsValid) return View(model);

Typo: IMessage should be IMessageService

Two typos have found their way into the book.
Where IMessage is used, substitute with IMessageService. The code here on GitHub is correct for this issue.

The book will be updated with the change soon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.