Adding Autofac to .NET core 6.0 using the new single file template

I found this Microsoft docs var builder = WebApplication.CreateBuilder(args); builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()); // Register services directly with Autofac here. // Don’t call builder.Populate(), that happens in AutofacServiceProviderFactory. builder.Host.ConfigureContainer<ContainerBuilder>( builder => builder.RegisterModule(new MyApplicationModule())); var app = builder.Build();

What is AddEndpointsApiExplorer in ASP.NET Core 6

AddEndpointsApiExplorer is for Minimal APIs whereas AddApiExplorer requires, at least, MVC Core. For API projects, AddControllers calls AddApiExplorer on your behalf. But Why Does Everything Still Work With AddEndpointsApiExplorer? With the introduction of Endpoint Routing, everything in the routing system boils down to an Endpoint. ASP.NET Core uses the Application Model, namely ApplicationModel, ControllerModel, and … Read more

Config connection string in .net core 6

Configuration.GetConnectionString(string connName) in .NET6 is under builder: var builder = WebApplication.CreateBuilder(args); string connString = builder.Configuration.GetConnectionString(“DefaultConnection”); also AddDbContext() is under builder.Services: builder.Services.AddDbContext<YourContext>(options => { options.UseSqlServer(builder.Configuration.GetConnectionString(“DefaultConnection”)); });