Stack Exchange
Passing many parameters to constructors of all components using Autofac
Sorry if the question is incorrect, I'm a junior.
I have the following code:
Class1 c1 = new Class1(DateTime.Today,
                       "123",
                       0,
                       new Class2("01001", @"E:\ATMSZ\Reg\BASE\REG2019.GDB", DateTime.Now, true) 
);
c1.Work();

How do I make it using Autofac?
Without passing the arguments, I got this:
var builder = new ContainerBuilder();
builder.RegisterType<Class2>().As<IClass2>(); 
var container = builder.Build();

var component = container.Resolve<Class1>();
component.Work();


Check this out https://autofaccn.readthedocs.io/en/latest/resolve/parameters.html

Where does these parameters come from ? do you know them when you register classes or at runtime ?Are you sure these parameters are relevant on the constructor on are not related to the Work method ?

@Cyril Durand

Transmitted from the shell in which the subroutine, whose code I wrote in the question.
I know during registration.
Yes, I'm sure!


You can use the WithParameter method to provide parameter during registration. 
builder.RegisterType<Class1>()
       .As<IClass1>()
       .WithParameter("date", DateTime.Today)
       .WithParameter("i", "123")
       .WithParameter(
           new ResolvedParameter(
               (pi, ctx) => pi.ParameterType == typeof(Class2) && pi.Name == "class2",
               (pi, ctx) => ctx.Resolve<IClass2>()));

or register them using lambda
builder.Register(ctx => new Class1(DateTime.Today, ..., ctx.Resolve<Class2>())
       .As<IClass1>(); 

