Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Plugging a Third-Party IoC Container (e.g. AutoFac) into .NET Core 6

var builder = WebApplication.CreateBuilder(args);

// The UseServiceProviderFactory call attaches the
// Autofac provider to the generic hosting mechanism.

builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());

// Add services to the container.
builder.Services.AddControllersWithViews();

//Register your own things directly with Autofac here
builder.Host.ConfigureContainer<ContainerBuilder>(builder => builder.RegisterType<Service>().As<IService>());

var app = builder.Build();
 
PREVIOUS NEXT
Tagged: #Plugging #IoC #Container #Core
ADD COMMENT
Topic
Name
9+7 =