Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConfigureServices in program.cs file?

Tags:

asp.net-core

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

like image 370
MTplus Avatar asked Oct 21 '25 06:10

MTplus


1 Answers

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")));
like image 75
serhatyt Avatar answered Oct 23 '25 22:10

serhatyt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!