Skip to content

Composites Lifetime

Sagi edited this page Apr 14, 2015 · 5 revisions

After NCop is done crafting the composite type it registers the new type in the IoC.
Currently NCop supports two types of composite lifecycle:

Transient - A new object is created for each logical request.

[TransientComposite]
[Mixins(typeof(CSharpDeveloperMixin))]
public interface IDeveloper : IDisposable
{
    void Code();
}

Singleton - Only one composite object instance will be created.

[SingletonComposite]
[Mixins(typeof(CSharpDeveloperMixin))]
public interface IDeveloper : IDisposable
{
    void Code();
}

Per Thread - Only one composite object instance will be created on a per-thread basis.

[PerThreadComposite]
[Mixins(typeof(CSharpDeveloperMixin))]
public interface IDeveloper : IDisposable
{
    void Code();
}

Per http request - A new object is created for each HTTP request.
(Will throw a LifetimeStragtegyException in case HttpContext.Current is null)

[PerHttpRequestComposite]
[Mixins(typeof(CSharpDeveloperMixin))]
public interface IDeveloper : IDisposable
{
    void Code();
}

Per hybrid request - PerHttpRequestComposite or PerThreadComposite
(depends on the context).

[PerHybridRequestComposite]
[Mixins(typeof(CSharpDeveloperMixin))]
public interface IDeveloper : IDisposable
{
    void Code();
}