working with generic lifetime managers in unity config section

Posted by Martin Bailey on Stack Overflow See other posts from Stack Overflow or by Martin Bailey
Published on 2010-04-28T07:26:12Z Indexed on 2010/04/28 8:33 UTC
Read the original article Hit count: 447

I have the following generic lifetime manager

    public class RequestLifetimeManager<T> : LifetimeManager, IDisposable
    {
    public override object GetValue()
    {
        return HttpContext.Current.Items[typeof(T).AssemblyQualifiedName];
    }
    public override void RemoveValue()
    {
        HttpContext.Current.Items.Remove(typeof(T).AssemblyQualifiedName);
    }
    public override void SetValue(object newValue)
    {
        HttpContext.Current.Items[typeof(T).AssemblyQualifiedName] = newValue;
    }
    public void Dispose()
    {
        RemoveValue();
    }
}

How do I reference this in the unity config section. Creating a type alias

<typeAlias alias="requestLifeTimeManager`1" type=" UI.Common.Unity.RequestLifetimeManager`1,  UI.Common" />

and specifying it as a lifetime manager

   <types>
    <type type="[interface]" mapTo="[concretetype]" >
      <lifetime type="requestLifeTimeManager`1"  />
    </type>
  </types>

causes the following error

Cannot create an instance of UI.Common.Unity.RequestLifetimeManager`1[T] because Type.ContainsGenericParameters is true. 

How do you reference generic lifetime managers ?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about unity