I create a processing object as follows during the start of a process:
using (var lifetime = EngineContext.Current.BeginLifetimeScope())
{
var sourceService = lifetime.Resolve<SourceService>();
// do things...
}
The SourceService class depends on other objects also registered with AutoFac - through constructor injection.
Do these objects automatically inherit the same lifetimescope as its 'parent' i.e. sourceService ?
It depends on how they were registered.
InstancePerLifetimeScope
= one per scope.
Example:
builder.Register<YourClass>()
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
You can read more here:
http://autofac.readthedocs.io/en/latest/lifetime/instance-scope.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With