working with generic lifetime managers in unity config section
- by Martin Bailey
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 ?