.NET core DI, autofac



I’m relatively new to .net core and there’s one thing that bothers me. In most of extensions e.g Mongo, there are multiple registration of types which are resolved in further ones. Could someone explain to me what is the benefit of such approach? I mean why not just register only one dependency (like mongo client) and there load all objects from configuration?

builder.Register(context =>
var configuration = context.Resolve < IConfiguration >();
var options = configuration.GetOptions(“mongo”);

return **options;**


builder.Register(context =>
var options = context.Resolve < MongoDbOptions>();

return new MongoClient(options.ConnectionString);


Second question:
Why do you use Autofac in most of cases instead of built-in .net core DI ?

Thanks for answers


I guess I have he similar question, since .Net Core had its own built-in DI schema, also I noticed in DShop.Common.Mvc, where the code just uses extension method of .Net DI instead of autofac, what’s the benefit of using autofac here? I know that autofac is a good tool for DI or IOC in old .Net framework(<=4.5), is there any special reason we should continue using it in .Net Core?