Home > Back-end >  ConfigureServices in program.cs file?
ConfigureServices in program.cs file?

Time:11-04

I try to follow this link https://www.tektutorialshub.com/asp-net-core/asp-net-core-identity-tutorial/ to add Identity core for a asp.net core web mvc project. But it mention I should configure service for dependency injection (ConfigureServices) in my startup.cs file, but I only have a program.cs file... Can someone please help me out and tell me how I can do this in the program.cs file instead (if its supposed to be done there...)

CodePudding user response:

It uses .NET Core 5.0 to implement that.

If you are using .NET Core 6.0, Program.cs and Startup.cs are combined there.

So you can use Program.cs to do anything you can do with .NET Core 5.0.

for example (in Program.cs)

var builder = WebApplication.CreateBuilder(args);
ConfigurationManager configuration = builder.Configuration; 

builder.Services.AddDbContext<ApplicationDbContext>(options =>
    options.UseSqlServer(
        configuration.GetConnectionString("DefaultConnection")));
  • Related