Search code examples
c#scopeautofac

Lifetime scope of the below transient class in autofac


I just started learning autofac and I am not sure about the lifetime scope of the below transient class.

builder.Register<MySampleClass>().As<IMySampleClass>();

Is a new instance created each time it is resolved or is it created once per thread or is it created and scoped when a new Task is created?


Solution

  • Yes, a new instance will be created each time your application calls Resolve in the same lifetime scope.

    You have other possibilities and I suggest you take a look at the official documentation.