Resolve type from config on demand

Feb 10, 2010 at 3:55 PM


I would like to change the default unity behivour  on ConfigurationManager.GetSection("unity");

I whould like it just to sign what is the config is  for each type

and actualy load it only when the first  calls of  Container.Resolve<> has invoked (per each type)

This is just for debug time when many pepole share same config file and i do not want them to share the types they  added  to the config

ofcourse on release Container will have all its types

IS their a way doing this  without dealing with the Microsoft.Practices.Unity.Configuration source code

I succeded doing this with try catch on the AssemblyQualifiedTypeNameConverter

so only when resolving types i get a object null exception (becuase the type is not loaded and its null (due to added try catch code)

but this is not so nice...

Feb 10, 2010 at 5:08 PM

I'm having a little trouble understanding your request, but if I follow you, Unity 2.0 may already do what you want. In 2.0, loading the section doesn't actually resolve any types (except for those needed to load the configuration itself, like section extensions), they're just stored as strings in the configuration section objects. The types aren't actually resolved until you apply the configuration to a container.


Feb 11, 2010 at 10:25 AM

Sorry For  my poor English...  and thnx for your quick reply.

On unity 2.0 as you said the resolve is when i call the config  not when i load the section .

I would like the resolve  (load types to app domain.  )   To happen per type,  Once  i call the _Container.Resolve<T>()

I Do not want the T type to be loaded to the app.domain  when i call  Configure()

In my point of view the Configure should just tell the Container once a Resolve is called which type to load not to actually load it.

So if a Type that is missing is not called in runtime _Container.Resolve(for missing type)  nothing is wrong .

 If we compare it to wcf config

Having  a wrong end point will throw  an exception only when i use it not on  reading  wcf config.

Is this behavior  possible in unity ?

Thnx yakijo.



Feb 11, 2010 at 5:59 PM

No, everything internal to Unity is keyed of System.Type objects. We need the assembly loaded in order to have that Type object.