Generic CustomLifetimeManager and configuration file declaration

Dec 8, 2008 at 9:43 AM
Hi,

How to use a configuration file to declare a generic customlifetimemanager ?, for example :

<unity>
    <types>
        <type type="IMyService" mapTo="ConcreteService">
            <lifetime type="HttpSessionLifetimeManager`1,MyAssembly"/>
    </types>
</unity> 

I have a error message like :

Can't create a HttpSessionLifetimeManager`1[T] because Type.ContainsGenericParameter is true

But when i programmatically declare those works

container.RegisterType<IMyService,ConcreteService>(new HttpSessionLifetimeManager<IMyService>());
 
Dec 8, 2008 at 6:22 PM
The configuration file and the API call are doing two very different things.

The API equivalent of your config file is:

container.RegisterType<IMyService, ConcreteService>(new HttpSessionLifetimeManager<>());

You've only specified the open generic in the config. You need to give a closed generic (i.e. specify the type inside the angle brackets). The Config file syntax to do this looks like this:

<lifetime type="HttpSessionLifetimeManager`1[[MyNamespace.IMyService, MyAssembly]], MyAssembly"/>

-Chris