Skip to content
Promote Your Product

Object Lifetime (Autofac)8.3.0

Transient

The transient lifetime means a new instance is created every time the service is requested from the container. Apply the attribute to the object:

[InjectTransient]
public class ModuleModel
{
}

Scoped

In web applications, the scoped lifetime means one instance is created per request (or session) and released when the request ends. Apply the attribute to the object:

[InjectScoped]
public class ModuleModel
{
}

Singleton

The singleton lifetime means each subsequent request from the container returns the same instance. Apply the attribute to the object:

[InjectSingleton]
public class ModuleModel
{
}