I have the following configuration in Autofac:
builder.Register<ServiceFactory>(x => y => x.Resolve<IComponentContext>().Resolve(y));
With this configuration I get the error:
System.ObjectDisposedException: This resolve operation has already ended. When registering components using lambdas, the IComponentContext 'c' parameter to the lambda cannot be stored. Instead, either resolve IComponentContext again from 'c', or resolve a Func<> based factory to create subsequent components from.
If I use the following than it works:
builder.Register<ServiceFactory>(x => {
IComponentContext context = x.Resolve<IComponentContext>();
return y => context.Resolve(y);
});
Can't this configuration be made in one code line?
What am I missing?