dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.63k stars 25.3k forks source link

Configure Facebook Authentication Code Section #11028

Closed alexmackey closed 5 years ago

alexmackey commented 5 years ago

The code snippet in Configure Facebook Authentication Code, ConfigureServices could be made clearer by either including the setup of dbcontext (e.g. below) or mention this snippet should be placed after the call to AddDbContext to avoid a confusing dependency resolution error.

services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection")));


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Rick-Anderson commented 5 years ago

@alexmackey The setup of ApplicationDbContext doesn't have anything directly to do with this tutorial. That should all be done in the previous tutorial, which is a prerequisite.

this snippet should be placed after the call to AddDbContext to avoid a confusing dependency resolution error.

It does show that.

services.AddDefaultIdentity<IdentityUser>()
        .AddDefaultUI(UIFramework.Bootstrap4)
        .AddEntityFrameworkStores<ApplicationDbContext>();

services.AddAuthentication().AddFacebook(facebookOptions =>
{
    facebookOptions.AppId = Configuration["Authentication:Facebook:AppId"];
    facebookOptions.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
});
alexmackey commented 5 years ago

Hey Rick I understand and maybe its just me but when I followed tutorial through I interpreted this as this code snippet replaced the existing code in configure services method which then led to the dependency resolution error (and 20 mins whilst I worked out what caused it).

E.g. if this read "Add the Facebook service in the ConfigureServices method in the Startup.cs file below the existing call to AddDbContext" this would be clearer?

Rick-Anderson commented 5 years ago

In the next sweep I'll add the entire ConfigureServices and highlight the code to add.

alexmackey commented 5 years ago

awesome! 👍