MTplus
MTplus

Reputation: 2391

ConfigureServices in program.cs file?

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...)

Upvotes: 3

Views: 8998

Answers (1)

serhatyt
serhatyt

Reputation: 425

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")));

Upvotes: 7

Related Questions